Question

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?

Was it helpful?

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.

OTHER TIPS

Then either you didn't type

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

exactly like this, on a single line. This is what I get:

> bash <- function() system("bash")
> bash()
[gavin@prometheus cocorresp_check]$ exit
> ls()
 [1] "a"       "b"       "bash"    "cars.lo" "dat"     "Dbig"    "Djackal"
 [8] "foo"     "i"       "jack.t"  "jackal"  "mat"     "mat2"    "meanDif"
[15] "mod"     "N"       "perm"    "x"       "Xa"      "Xab"     "Xb"     
[22] "xct"     "y"
> match.fun("bash")
function() system("bash")

Note that bash() is the third object listed. So the first line defines the function, I use it on the second line to drop to a bash shell, which I promptly exit returning me to the R prompt.

If the function isn't defined in your working environment then whatever you did to define it didn't work. It would appear from your description that R just executed system("bash").

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top