Reduce the size and complexity of a analytical script through algorithmic detection of the essential code needed to produce a set of results.

clean(script, vars, format = TRUE)

Arguments

script

File path to a script or a Script object from CodeDepends.

vars

The name of the variable(s) of interest.

format

LOGICAL: should the minimized code be re-formatted following common syntax style guides?

Value

A character vector containing a minimized script based on the given input variable or set of variables.

Author

Matthew K. Lau

Examples

script <- system.file( "example", "simple_script.R", package = "Rclean") clean(script)
#> [1] "Please supply at least one variable:"
#> [1] "mat" "dat" "fit12" "fit13" "fit14" "fit15.aov" #> [7] "tab.12" "tab.13" "tab.14" "tab.15" "out"
clean(script, "mat")
#> Warning: Could not use colored = TRUE, as the package prettycode is not installed. Please install it if you want to see colored output or see `?print.vertical` for more information.
#> mat <- matrix(rnorm(400), nrow = 100)
clean(script, "tab.12")
#> Warning: Could not use colored = TRUE, as the package prettycode is not installed. Please install it if you want to see colored output or see `?print.vertical` for more information.
#> mat <- matrix(rnorm(400), nrow = 100) #> dat <- as.data.frame(mat) #> dat[, "V2"] <- dat[, "V2"] + runif(nrow(dat)) #> dat[, "V5"] <- gl(10, 10) #> fit12 <- lm(V1 ~ V2, data = dat) #> tab.12 <- summary(fit12) #> dat <- 25 + 2 #> dat[2] <- 10
clean(script, c("mat", "tab.12", "out"))
#> Warning: Could not use colored = TRUE, as the package prettycode is not installed. Please install it if you want to see colored output or see `?print.vertical` for more information.
#> mat <- matrix(rnorm(400), nrow = 100) #> dat <- as.data.frame(mat) #> dat[, "V2"] <- dat[, "V2"] + runif(nrow(dat)) #> dat[, "V5"] <- gl(10, 10) #> fit12 <- lm(V1 ~ V2, data = dat) #> tab.12 <- summary(fit12) #> dat <- 25 + 2 #> dat[2] <- 10 #> out <- dat * 2