Search code examples
bashrdevtools

What does bash in the devtools package do?


In response to a previous question, Alternatives to system() in R for calling sed, rsync, ssh etc.: Do functions exist, should I write my own, or am I missing the point?, hadley's answer indicated that when faced with a similar problem, he had used a function like:

bash <- function() system("bash")

I found the original in his devtools package; implemented in devtools/R/bash.R:

#' Open bash shell in package directory.
#'
#' @param pkg package description, can be path or package name.  See
#'   \code{\link{as.package}} for more information
#' @export
bash <- function(pkg = NULL) {
  pkg <- as.package(pkg)

  in_dir(pkg$path, system("bash"))
}

I don't understand the point of this. When I issue

bash <- function() system("bash")

It sends me to the bash shell, after which exit returns me to the R session, but there is no bash function. It seems that I can get the same effect by either issuing either of the following command pairs (first command in R, second in bash)

system('bash')
exit

or

q('yes')
R

the striked part were due to a copy/paste error on my part

I also can not find any further uses of the bash function in the devtools package

Can someone please help me understand how the bash function could be used; can it be used in contexts (e.g. within scripts or functions) other than interactive R mode?


Solution

  • Earlier versions of devtools included some functionality to push/pull code to git/github. This has now been deprecated.

    Instead, the convenience function bash simply opens a bash editor in the package directory. This means you can use command line tools to interact with git/github.

    The purpose of bash is simply to save a few keystrokes to open the command line in the package directory. It serves no other function.