Learn R Programming

aprof (version 0.4.1)

aprof: Create an 'aprof' object for usage in the package 'aprof'

Description

Create 'aprof' objects for usage with 'aprof' functions

Usage

aprof(src = NULL, output = NULL)

Arguments

src

The name of the source code file (and path if not in the working directory). The source code file is expected to be a a plain text file (e.g. txt, .R), containing the code of the previously profiled program. If left empty, some "aprof" functions (e.g. readLineDensity) will attempt to extract this information from the call stack but this is not recommended (as the success of file name detection operations vary). Note that functions that require a defined source file will fail if the source file is not defined or detected in the call stack.

output

The file name (and path if not in the working directory) of a previously created profiling exercise.

Value

An aprof object

Details

Creates an "aprof" object from the R-profiler's output and a source file. The objects created through "aprof" can be used by the standard functions plot, summary and print (more specifically: plot.aprof, summary.aprof and print.arof). See the example below for more details.

Using aprof with knitr and within .Rmd or .Rnw documents is not yet supported by the R profiler. Note that setting the chuck option: engine="Rscript", disables line-profiling. Line profiling only works in a interactive session (Oct 2015). In these cases users are advised to use the standard Rprof functions or "profr" (while setting engine="Rscript") and not to rely on line-profiling based packages (for the time being).

See Also

plot.aprof, summary.aprof, print.aprof, Rprof and summaryRprof.

Examples

Run this code
# NOT RUN {
   ## create function to profile
     foo <- function(N){
             preallocate<-numeric(N)
             grow<-NULL
              for(i in 1:N){
                  preallocate[i]<-N/(i+1)
                  grow<-c(grow,N/(i+1))
                 }
     }

     ## save function to a source file and reload
     dump("foo",file="foo.R")
     source("foo.R")

     ## create file to save profiler output
     tmp<-tempfile()

     ## Profile the function
     Rprof(tmp,line.profiling=TRUE)
     foo(1e4)
     Rprof(append=FALSE)

     ## Create a aprof object
     fooaprof<-aprof("foo.R",tmp)
     ## display basic information, summarize and plot the object
     fooaprof
     summary(fooaprof)
     plot(fooaprof)
     profileplot(fooaprof)

     ## To continue with memory profiling:
     ## enable memory.profiling=TRUE
     Rprof(tmp,line.profiling=TRUE,memory.profiling=TRUE)
     foo(1e4)
     Rprof(append=FALSE)
     ## Create a aprof object
     fooaprof<-aprof("foo.R",tmp)
     ## display basic information, and plot memory usage
     fooaprof
     
     plot(fooaprof)
   
# }

Run the code above in your browser using DataLab