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

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/aprof.R

Description

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

Usage

1
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.

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).

Value

An aprof object

Author(s)

Marco D. Visser

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
## 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)
   

## End(Not run)

MarcoDVisser/aprof documentation built on Jan. 18, 2020, 9:15 p.m.