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
R CMD <custom>?
10 messages · Yihui Xie, William Dunlap, Hadley Wickham +2 more
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:
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
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/
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:
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:
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
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
-- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
On 28/11/2011 2:16 PM, Henrik Bengtsson wrote:
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).
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:
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.
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 does seem to mix up namespaces quite a bit.
That was just a proposal - equally R CMD mypackage::mycommand could just run mypackage::mycommand() but then passing argument might get a bit confusing.
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).
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
Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/
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
-----Original Message-----
From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org] On Behalf Of Hadley Wickham
Sent: Monday, November 28, 2011 11:49 AM
To: Henrik Bengtsson
Cc: R-devel
Subject: Re: [Rd] R CMD <custom>?
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:
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
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
-- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
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'.
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
Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/
On Mon, Nov 28, 2011 at 12:19 PM, Hadley Wickham <hadley at rice.edu> wrote:
That does seem to mix up namespaces quite a bit.
That was just a proposal - equally R CMD mypackage::mycommand could just run mypackage::mycommand() but then passing argument might get a bit confusing.
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).
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.
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
Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
On 11-11-28 3:19 PM, Hadley Wickham wrote:
That does seem to mix up namespaces quite a bit.
That was just a proposal - equally R CMD mypackage::mycommand could just run mypackage::mycommand() but then passing argument might get a bit confusing.
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).
Because you have to specify the path to that package?
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
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.
"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
Hadley