diff --git a/DESCRIPTION b/DESCRIPTION index 30b4bec..a014ed5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: proffer Title: Profile R Code and Visualize with 'Pprof' -Version: 0.1.2.9000 +Version: 0.1.3 Encoding: UTF-8 Language: en-US License: MIT + file LICENSE diff --git a/NEWS.md b/NEWS.md index 851a41f..fe3c3a3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ -# proffer 0.1.2.9000 - +# proffer 0.1.3 +* Reduce check time of examples. # proffer 0.1.2 diff --git a/R/package.R b/R/package.R index 61b7b25..2480c0f 100644 --- a/R/package.R +++ b/R/package.R @@ -23,7 +23,7 @@ #' @importFrom utils browseURL Rprof #' @importFrom withr with_path #' @examples -#' \dontrun{ +#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { #' # Start a pprof virtual server in the background. #' px <- pprof(replicate(1e2, sample.int(1e4))) #' # Terminate the server. diff --git a/R/path.R b/R/path.R index b159136..9638944 100644 --- a/R/path.R +++ b/R/path.R @@ -6,7 +6,7 @@ #' for setup instructions. #' @return Character, path to `pprof` it exists and `""` otherwise. #' @examples -#' \dontrun{ +#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { #' pprof_path() #' } pprof_path <- function() { diff --git a/R/pprof.R b/R/pprof.R index 921c912..5cb14a6 100644 --- a/R/pprof.R +++ b/R/pprof.R @@ -7,7 +7,7 @@ #' for setup instructions. #' @inheritParams pprof #' @examples -#' \dontrun{ +#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { #' test_pprof() #' } test_pprof <- function( @@ -45,7 +45,7 @@ test_pprof <- function( #' @param ... Additional arguments passed on to [Rprof()] #' via [record_pprof()]. #' @examples -#' \dontrun{ +#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { #' # Start a pprof virtual server in the background. #' px <- pprof(replicate(1e2, sample.int(1e4))) #' # Terminate the server. @@ -82,7 +82,7 @@ pprof <- function( #' @param rprof Path to profiling samples generated #' by `Rprof()` or [record_rprof()]. #' @examples -#' \dontrun{ +#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { #' rprof <- record_rprof(replicate(1e2, sample.int(1e4))) #' # Start a pprof virtual server in the background. #' px <- serve_rprof(rprof) @@ -129,7 +129,7 @@ serve_rprof <- function( #' @param verbose Logical, whether to print console messages #' such as the URL of the local `pprof` server. #' @examples -#' \dontrun{ +#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { #' pprof <- record_pprof(replicate(1e2, sample.int(1e4))) #' # Start a pprof virtual server in the background. #' px <- serve_pprof(pprof) @@ -162,6 +162,8 @@ serve_pprof <- function( #' @return Port number, positive integer of length 1. #' @param lower Integer of length 1, lower bound of the port number. #' @param upper Integer of length 1, upper bound of the port number. +#' @examples +#' random_port() random_port <- function(lower = 49152L, upper = 65355L) { sample(seq.int(from = lower, to = upper, by = 1L), size = 1L) } diff --git a/R/record.R b/R/record.R index e002dfa..1f4a463 100644 --- a/R/record.R +++ b/R/record.R @@ -10,8 +10,10 @@ #' @param ... Additional arguments passed on to [Rprof()] #' via [record_rprof()]. #' @examples +#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { #' # Returns a path to pprof samples. #' record_pprof(replicate(1e2, sample.int(1e4))) +#' } record_pprof <- function(expr, pprof = tempfile(), ...) { rprof <- record_rprof(expr, ...) to_pprof(rprof, pprof = pprof) @@ -27,8 +29,10 @@ record_pprof <- function(expr, pprof = tempfile(), ...) { #' Also returned from the function. #' @param ... Additional arguments passed on to [Rprof()]. #' @examples +#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { #' # Returns a path to Rprof samples. #' record_rprof(replicate(1e2, sample.int(1e4))) +#' } record_rprof <- function(expr, rprof = tempfile(), ...) { on.exit(Rprof(NULL)) Rprof(filename = rprof, ...) @@ -43,8 +47,10 @@ record_rprof <- function(expr, rprof = tempfile(), ...) { #' @param rprof Path to Rprof samples. #' @param pprof Path to pprof samples. #' @examples +#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { #' rprof <- record_rprof(replicate(1e2, sample.int(1e4))) #' to_pprof(rprof) +#' } to_pprof <- function(rprof, pprof = tempfile()) { samples <- profile::read_rprof(path = rprof) profile::write_pprof(x = samples, path = pprof) @@ -58,8 +64,10 @@ to_pprof <- function(rprof, pprof = tempfile()) { #' @param pprof Path to pprof samples. #' @param rprof Path to Rprof samples. #' @examples +#' if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { #' pprof <- record_pprof(replicate(1e2, sample.int(1e4))) #' to_rprof(pprof) +#' } to_rprof <- function(pprof, rprof = tempfile()) { samples <- profile::read_pprof(path = pprof) profile::write_rprof(x = samples, path = rprof) diff --git a/man/pprof.Rd b/man/pprof.Rd index c5b9e36..064a531 100644 --- a/man/pprof.Rd +++ b/man/pprof.Rd @@ -46,7 +46,7 @@ in a local interactive pprof server. Results are collected with \code{\link[=record_pprof]{record_pprof()}}. } \examples{ -\dontrun{ +if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { # Start a pprof virtual server in the background. px <- pprof(replicate(1e2, sample.int(1e4))) # Terminate the server. diff --git a/man/pprof_path.Rd b/man/pprof_path.Rd index f6e64bf..79fe3bb 100644 --- a/man/pprof_path.Rd +++ b/man/pprof_path.Rd @@ -18,7 +18,7 @@ See \url{https://github.com/r-prof/proffer#installation} for setup instructions. } \examples{ -\dontrun{ +if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { pprof_path() } } diff --git a/man/proffer-package.Rd b/man/proffer-package.Rd index 051ed5e..f943ca4 100644 --- a/man/proffer-package.Rd +++ b/man/proffer-package.Rd @@ -18,7 +18,7 @@ For documentation, visit \url{https://r-prof.github.io/proffer/}. } \examples{ # TBD -\dontrun{ +if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { # Start a pprof virtual server in the background. px <- pprof(replicate(1e2, sample.int(1e4))) # Terminate the server. diff --git a/man/random_port.Rd b/man/random_port.Rd index abe4ccb..dda6150 100644 --- a/man/random_port.Rd +++ b/man/random_port.Rd @@ -18,3 +18,6 @@ Port number, positive integer of length 1. Choose a random TCP port that is unlikely to be occupied by another process. } +\examples{ +random_port() +} diff --git a/man/record_pprof.Rd b/man/record_pprof.Rd index 19c61e2..7c19eb7 100644 --- a/man/record_pprof.Rd +++ b/man/record_pprof.Rd @@ -24,6 +24,8 @@ Profiles are recorded with \code{\link[=record_rprof]{record_rprof()}} and then converted with \code{\link[=to_pprof]{to_pprof()}}. } \examples{ +if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { # Returns a path to pprof samples. record_pprof(replicate(1e2, sample.int(1e4))) } +} diff --git a/man/record_rprof.Rd b/man/record_rprof.Rd index 7d3c2d8..e21a680 100644 --- a/man/record_rprof.Rd +++ b/man/record_rprof.Rd @@ -21,6 +21,8 @@ Path to a file with Rprof samples. Run R code and record Rprof samples. } \examples{ +if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { # Returns a path to Rprof samples. record_rprof(replicate(1e2, sample.int(1e4))) } +} diff --git a/man/serve_pprof.Rd b/man/serve_pprof.Rd index 1a70771..eae83df 100644 --- a/man/serve_pprof.Rd +++ b/man/serve_pprof.Rd @@ -45,7 +45,7 @@ Navigate a browser to a URL in the message. The server starts in a background process } \examples{ -\dontrun{ +if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { pprof <- record_pprof(replicate(1e2, sample.int(1e4))) # Start a pprof virtual server in the background. px <- serve_pprof(pprof) diff --git a/man/serve_rprof.Rd b/man/serve_rprof.Rd index 84942f6..30a07e0 100644 --- a/man/serve_rprof.Rd +++ b/man/serve_rprof.Rd @@ -47,7 +47,7 @@ Navigate a browser to a URL in the message. The server starts in a background process } \examples{ -\dontrun{ +if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { rprof <- record_rprof(replicate(1e2, sample.int(1e4))) # Start a pprof virtual server in the background. px <- serve_rprof(rprof) diff --git a/man/test_pprof.Rd b/man/test_pprof.Rd index 18caa4a..d532970 100644 --- a/man/test_pprof.Rd +++ b/man/test_pprof.Rd @@ -38,7 +38,7 @@ See \url{https://github.com/r-prof/proffer#installation} for setup instructions. } \examples{ -\dontrun{ +if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { test_pprof() } } diff --git a/man/to_pprof.Rd b/man/to_pprof.Rd index 31cb64f..4108dfa 100644 --- a/man/to_pprof.Rd +++ b/man/to_pprof.Rd @@ -18,6 +18,8 @@ Path to pprof samples. Convert Rprof samples to pprof format. } \examples{ +if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { rprof <- record_rprof(replicate(1e2, sample.int(1e4))) to_pprof(rprof) } +} diff --git a/man/to_rprof.Rd b/man/to_rprof.Rd index 76d04f2..93248bd 100644 --- a/man/to_rprof.Rd +++ b/man/to_rprof.Rd @@ -18,6 +18,8 @@ Path to pprof samples. Convert pprof samples to Rprof format. } \examples{ +if (identical(Sys.getenv("PROFFER_EXAMPLES"), "true")) { pprof <- record_pprof(replicate(1e2, sample.int(1e4))) to_rprof(pprof) } +}