The Rclean package provides a set of functions to isolate the essential parts of a script that produces a chosen result, such as an object, table and/or figure.

Author

Matthew K. Lau [email protected]

Examples

## Define the path for your script script <- system.file( "example", "simple_script.R", package = "Rclean") ## Get a list of the variables in your script get_vars(script)
#> [1] "mat" "dat" "fit12" "fit13" "fit14" "fit15.aov" #> [7] "tab.12" "tab.13" "tab.14" "tab.15" "out"
## Take a look at the relationships in your script code_graph(script)
## Pick a result and isolate the code clean(script, "tab.15")
#> 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) #> fit14 <- lm(V1 ~ V4, data = dat) #> fit15.aov <- aov(V1 ~ V2 + V5, data = dat) #> tab.14 <- summary(fit14) #> tab.15 <- append(fit15.aov, tab.14) #> dat <- 25 + 2 #> dat[2] <- 10
## You can also select multiple results at the same time! my.vars <- c("tab.12", "tab.15") clean(script, my.vars)
#> 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) #> fit14 <- lm(V1 ~ V4, data = dat) #> fit15.aov <- aov(V1 ~ V2 + V5, data = dat) #> tab.12 <- summary(fit12) #> tab.14 <- summary(fit14) #> tab.15 <- append(fit15.aov, tab.14) #> dat <- 25 + 2 #> dat[2] <- 10