profile_script
profile_script.Rd
This function will add profiling code to a script wherever the following flags are found in the first non-spacing characters on the line:
#<p
Opening comment flag whereprofile_open
will be inserted.#>p
Closing comment flag whereprofile_close
will be inserted.
Usage
profile_script(
.file,
profile_open = utils::Rprof(fs::path(dir_profvis, ext(basename(.file), strip = TRUE),
glue::glue("{.lo}-{.lc}_{file_timestamp()}"), ext = "Rprof"), interval = 0.02,
line.profiling = TRUE, memory.profiling = TRUE),
profile_close = utils::Rprof(NULL),
dir_profvis = "profvis",
remove = FALSE,
new_script = TRUE,
new_filename = paste0(ext(basename(.file), strip = TRUE), "_prof", ext(.file))
)
Arguments
- .file
path to script
- profile_open
(expression)
The code that will be added preceding the opening comment flag. Consider usingglue
such that internal variables can be used for file naming conventions. In addition the function arguments, the following variable names can be used:.lo
Short for line open, the line number of the opening profile code..lc
Short for line close, the line number of the closing profile code.
Default:
utils::Rprof(fs::path(dir_profvis, basename(.x), glue::glue('{.lo}-{.lc}'), ext = "Rprof"), interval = .01, line.profiling = TRUE, gc.profiling = TRUE, memory.profiling = TRUE)
. Ifprofile_script
were called on a script calledscript.R
with opening flag at line 20 and closing flag at line 30, then line 20 would be changed as follows:utils::Rprof("profvis/script.R/20-30.Rprof", interval = 0.01, line.profiling = TRUE, gc.profiling = TRUE, memory.profiling = TRUE) #<p
.- profile_close
(expression)
The code that will be added preceding the closing comment flag. Default:utils::Rprof(NULL)
- dir_profvis
(character)
The directory in which allprofvis
related files will be put. Default:"profvis"
. Profile-ready script copies (ifnew_scripts = TRUE
) and Rprof files/directories will be placed here. Set toNULL
to use the working directory and overwrite existing files.- remove
(logical/character)
to indicate whether to remove profiling code. Default: FALSE. Change toTRUE
to remove profile code but leave flags. Change to"f"/"flags"
to remove code and flags. Remove modifies.file
in place.- new_script
(logical)
to indicate whether to write new profile-ready script copies todir_profvis
. Default: TRUE, ifFALSE
the character vector output of the profile-ready script lines from the function can be written to a file manually.