Skip to content

R CMD <custom>?

10 messages · Yihui Xie, William Dunlap, Hadley Wickham +2 more

#
Hi,

is it possible to add a custom script such that it is called via R CMD
<custom>?  Is R CMD searching for it elsewhere than R_HOME/bin/?  I'm
looking for an non-admin alternative, so copying the script to
R_HOME/bin/ will not do (in case the user don't have enough permission
to write there).

/Henrik
#
It'd be cool if R CMD was user extensible through packages, so that (e.g.)

R CMD mypackage::mycommand

would do something like:

path <- system.file("cmd", paste(command, ".r"), package = package)
if (!file.exists(path)) {
  stop("Command ", command, " in ", package, " does not exist")
} else {
  source(path)
}

And maybe `R CMD mypackage` would look in mypackcage/cmd/default.r.

Hadley
On Mon, Nov 28, 2011 at 1:16 PM, Henrik Bengtsson <hb at biostat.ucsf.edu> wrote:

  
    
#
I strongly support this proposal. This will be a fantastic feature!

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
On Mon, Nov 28, 2011 at 1:48 PM, Hadley Wickham <hadley at rice.edu> wrote:
#
On 28/11/2011 2:16 PM, Henrik Bengtsson wrote:
I don't remember if this is platform independent,  but

R CMD foo

on Windows will set up standard environment variables then try to 
execute "foo".  If "foo" isn't one of the internal commands listed by

R CMD --help

then it will just go looking for it like any other command in the path.  
(This is why "R CMD install" gives a funny error message:  the internal 
command is "INSTALL", so "R CMD install" just tries to execute "install".)

Duncan Murdoch
#
On 28/11/2011 2:48 PM, Hadley Wickham wrote:
That does seem to mix up namespaces quite a bit.  But what does it get 
you that "Rscript -e" doesn't already give you?  You can set up your 
package so that

R CMD mypackage::mycommand

executes a function, using delayedAssign or some of the more exotic 
features (like external pointers and finalizers).

Duncan Murdoch
#
That was just a proposal - equally

R CMD mypackage::mycommand

could just run

mypackage::mycommand()

but then passing argument might get a bit confusing.
Because you have to specify the path to that package?  R CMD roxygen2
is much easier to type, remember and is portable, compared to
~/R/roxygen2/something.r.  It also makes R CMD scripts extensible by
packages in a consistent manner.

Hadley
#
The shell command
  R CMD something
currently acts as though it puts R_HOME/bin on the front
of PATH, looks for an executable file called 'something'
in PATH, and then executes it.  The executable may call R
or it may not.

I think that running an R script file is sufficiently different
from running an executable file that the operation should
not also be called 'CMD'.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
#
Fair enough. But it would still be extremely useful to have an R
"command" which did run R scripts (which naively you would expect R
CMD to do do).  Maybe R SCRIPT ?

Or R CMD package::script could look for an arbitrary script and
execute it - I suspect this would be trickier cross-platform though.

One could also consider eliminating R CMD and the bin directory, given
that most of the scripts there now just call an R function.  Perhaps a
general syntax for calling R scripts in an package could subsume these
important scripts in a consistent and package-extensible manner.

Hadley
#
On Mon, Nov 28, 2011 at 12:19 PM, Hadley Wickham <hadley at rice.edu> wrote:
When people run R CMD build, R CMD INSTALL, R CMD check etc, they are
in a well defined working directory.  It can be assumed that R CMD
roxygen2 will be executed in the same directory.  As so as you enter
the R prompt, you cannot assume this working directory, and you have
to document/specify which directory the command should be executed on.
 Because of this, I favor an 'R CMD roxygen2' solution.

My use case/wish is to be able to provide 'R CMD Rdoc' (similar to 'R
CMD roxygen2') and 'R CMD rsp' (similar to 'R CMD Sweave').

/Henrik
#
On 11-11-28 3:19 PM, Hadley Wickham wrote:
Sorry, I was in a rush and typed the wrong thing.  I meant to type

Rscript -e mypackage::mycommand

which needs no path.

R CMD roxygen2
"Easier to type" is not a good argument, since any reasonable command 
line shell would allow you to abbreviate whatever you wanted.  "rox" is 
easier to type than R CMD roxygen2, and is easy enough to make happen.

Duncan Murdoch