Permalink
Browse files

Clean source to source in fresh R session

  • Loading branch information...
1 parent 47c183c commit 5099739e37ad1a4a6020843fe550005e6003819f @hadley committed Oct 18, 2011
Showing with 42 additions and 0 deletions.
  1. +1 −0 DESCRIPTION
  2. +1 −0 NAMESPACE
  3. +21 −0 R/source.r
  4. +1 −0 R/system.r
  5. +18 −0 man/clean_source.Rd
View
@@ -41,3 +41,4 @@ Collate:
'os.r'
'zzz.r'
'wd.r'
+ 'source.r'
View
@@ -5,6 +5,7 @@ export(build_win)
export(build)
export(check_doc)
export(check)
+export(clean_source)
export(dev_mode)
export(document)
export(has_devel)
View
@@ -0,0 +1,21 @@
+#' Sources an R file in a clean environment.
+#'
+#' Opens up a fresh R environment and sources file, ensuring that it works
+#' independently of the current working environment.
+#'
+#' @param path path to R script
+#' @param vanilla if \code{TRUE} tells R not to use any system specific
+#' settings.
+#' @export
+clean_source <- function(path, vanilla = FALSE) {
+ stopifnot(file.exists(path))
+
+ if (vanilla) {
+ opts <- c("--no-restore", "--no-save")
+ } else {
+ opts <- c("--vanilla")
+ }
+
+ opts <- c("--quiet", paste("--file=", shQuote(path), sep = ""))
+ R(opts, dirname(path))
+}
View
@@ -8,5 +8,6 @@ system_check <- function(cmd) {
R <- function(options, path = tempdir()) {
r_path <- shQuote(file.path(R.home("bin"), "R"))
+ options <- paste(options, collapse = " ")
in_dir(path, system_check(paste(r_path, options)))
}
View
@@ -0,0 +1,18 @@
+\name{clean_source}
+\alias{clean_source}
+\title{Sources an R file in a clean environment.}
+\usage{
+ clean_source(path, vanilla = FALSE)
+}
+\arguments{
+ \item{path}{path to R script}
+
+ \item{vanilla}{if \code{TRUE} tells R not to use any
+ system specific settings.}
+}
+\description{
+ Opens up a fresh R environment and sources file, ensuring
+ that it works independently of the current working
+ environment.
+}
+

0 comments on commit 5099739

Please sign in to comment.