Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export RCMD function so it can be used in other packages. #699

Merged
merged 4 commits into from
Jan 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ S3method(remote_metadata,url_remote)
S3method(replay_stop,default)
S3method(replay_stop,error)
S3method(replay_stop,list)
export(RCMD)
export(add_path)
export(add_rstudio_project)
export(add_test_infrastructure)
Expand Down Expand Up @@ -108,6 +109,7 @@ export(show_news)
export(source_gist)
export(source_url)
export(submit_cran)
export(system_check)
export(test)
export(unload)
export(use_appveyor)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# devtools 1.7.1.9000

* export functions `RCMD()` and `system_check()` so they can be used by other packages. (@jimhester, #699).

# devtools 1.7.0

## Improve reverse dependency checking
Expand Down
17 changes: 13 additions & 4 deletions R/R.r
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ R <- function(options, path = tempdir(), env_vars = NULL, ...) {
in_dir(path, system_check(r_path, options, c(r_env_vars(), env_vars), ...))
}

#' Run R CMD xxx from within R
#'
#' @param cmd one of the R tools available from the R CMD interface.
#' @param options a charater vector of options to pass to the command
#' @param path the directory to run the command in.
#' @param env_vars environment variables to set before running the command.
#' @param ... additional arguments passed to \code{\link{system_check}}
#' @return \code{TRUE} if the command succeeds, throws an error if the command
#' fails.
#' @export
RCMD <- function(cmd, options, path = tempdir(), env_vars = NULL, ...) {
options <- paste(options, collapse = " ")
R(paste("CMD", cmd, options), path = path, env_vars = env_vars, ...)
Expand All @@ -21,7 +31,7 @@ RCMD <- function(cmd, options, path = tempdir(), env_vars = NULL, ...) {
#'
#' Devtools sets a number of environmental variables to ensure consistent
#' between the current R session and the new session, and to ensure that
#' everying behaves the same across systems. It also suppresses a common
#' everything behaves the same across systems. It also suppresses a common
#' warning on windows, and sets \code{NOT_CRAN} so you can tell that your
#' code is not running on CRAN.
#'
Expand All @@ -32,9 +42,9 @@ r_env_vars <- function() {
c("R_LIBS" = paste(.libPaths(), collapse = .Platform$path.sep),
"CYGWIN" = "nodosfilewarning",
# When R CMD check runs tests, it sets R_TESTS. When the tests
# themeselves run R CMD xxxx, as is the case with the tests in
# themselves run R CMD xxxx, as is the case with the tests in
# devtools, having R_TESTS set causes errors because it confuses
# the R subprocesses. Unsetting it here avoids those problems.
# the R subprocesses. Un-setting it here avoids those problems.
"R_TESTS" = "",
"NOT_CRAN" = "true",
"TAR" = auto_tar())
Expand All @@ -52,4 +62,3 @@ auto_tar <- function() {
no_rtools <- is.null(get_rtools_path())
if (windows && no_rtools) "internal" else ""
}

13 changes: 10 additions & 3 deletions R/system.r
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @param arg a vector of command arguments.
# @param env a named character vector of environment variables. Will be quoted
#' Run a system command and check if it succeeds.
#'
#' @param cmd the command to run.
#' @param args a vector of command arguments.
#' @param env a named character vector of environment variables. Will be quoted
#' @param quiet if \code{FALSE}, the command to be run will be echoed.
#' @param ... additional arguments passed to \code{\link[base]{system}}
#' @return \code{TRUE} if the command succeeds, an error will be thrown if the
#' command fails.
#' @export
system_check <- function(cmd, args = character(), env = character(),
quiet = FALSE, ...) {
full <- paste(shQuote(cmd), " ", paste(args, collapse = ", "), sep = "")
Expand Down Expand Up @@ -32,4 +40,3 @@ wrap_command <- function(x) {
continue <- c(rep(" \\", length(lines) - 1), "")
paste(lines, continue, collapse = "\n")
}

27 changes: 27 additions & 0 deletions man/RCMD.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/R.r
\name{RCMD}
\alias{RCMD}
\title{Run R CMD xxx from within R}
\usage{
RCMD(cmd, options, path = tempdir(), env_vars = NULL, ...)
}
\arguments{
\item{cmd}{one of the R tools available from the R CMD interface.}

\item{options}{a charater vector of options to pass to the command}

\item{path}{the directory to run the command in.}

\item{env_vars}{environment variables to set before running the command.}

\item{...}{additional arguments passed to \code{\link{system_check}}}
}
\value{
\code{TRUE} if the command succeeds, throws an error if the command
fails.
}
\description{
Run R CMD xxx from within R
}

2 changes: 1 addition & 1 deletion man/r_env_vars.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ a named character vector
\description{
Devtools sets a number of environmental variables to ensure consistent
between the current R session and the new session, and to ensure that
everying behaves the same across systems. It also suppresses a common
everything behaves the same across systems. It also suppresses a common
warning on windows, and sets \code{NOT_CRAN} so you can tell that your
code is not running on CRAN.
}
Expand Down
28 changes: 28 additions & 0 deletions man/system_check.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/system.r
\name{system_check}
\alias{system_check}
\title{Run a system command and check if it succeeds.}
\usage{
system_check(cmd, args = character(), env = character(), quiet = FALSE,
...)
}
\arguments{
\item{cmd}{the command to run.}

\item{args}{a vector of command arguments.}

\item{env}{a named character vector of environment variables. Will be quoted}

\item{quiet}{if \code{FALSE}, the command to be run will be echoed.}

\item{...}{additional arguments passed to \code{\link[base]{system}}}
}
\value{
\code{TRUE} if the command succeeds, an error will be thrown if the
command fails.
}
\description{
Run a system command and check if it succeeds.
}