[Rd] R CMD BATCH vs R CMD batch

Rainer M Krug Rainer at krugs.de
Thu Oct 29 12:17:03 CET 2015


peter dalgaard <pdalgd at gmail.com> writes:

> On 29 Oct 2015, at 10:44 , Rainer M Krug <Rainer at krugs.de> wrote:
>
>> Out of interest: What is the magic ~R CMD~ is doing? Is it documented
>> anywhere?
>
>
> R is open source.... (and shell scripts are considered self-documenting by some)

True - should have looked in the sources...

>
> On Unix-alikes, R is a shell script which, if called with 1st argument
> CMD, calls ${R_HOME}/bin/Rcmd, which is another shell script that ends
> with
>
> case "${1}" in
> ## this was a separate command prior to 2.10.0
>   Rd2txt)
>     cmd="${R_HOME}/bin/Rdconv"
>     extra="-t txt"
>     ;;
> ## removed in 2.15.0
>   Rd2dvi)
>     echo "R CMD Rd2dvi is defunct: use Rd2pdf instead"
>     exit 1
>     ;;
>   *)
>     if test -x "${R_HOME}/bin/${1}"; then
>       cmd="${R_HOME}/bin/${1}"
>     else
>       cmd="${1}"
>     fi
>     ;;
> esac
> shift
>
> exec "${cmd}" ${extra} "${@}"
>
> I.e., except for setting up variables and such, R CMD ${foo}
> essentially looks for ${R_HOME}/bin/${foo} and executes it if it
> exists and is executable, otherwise it just executes ${foo}.

Thanks for that detailed explanation of the mechanism - it is much
clearer now. And as usual, if one knows how something is happening, it's
not "magical" anymore. 

>
> Notice that, somewhat contrary to what Dirk said, this logic works at
> the mercy of the file system when it comes to case sensitivity. On OSX
> with the default case-insensitive setup we get
>
> Peters-iMac:IBP pd$ R CMD install
> Error: ERROR: no packages specified
>
> which comes from R's package installer, whereas a case-sensitive FS
> would pick up /usr/bin/install instead. That is just how the "test"
> shell built-in works:
>
> Peters-iMac:~ pd$ test -x `R RHOME`/bin/INSTALL ; echo $?
> 0
> Peters-iMac:~ pd$ test -x `R RHOME`/bin/UNSTALL ; echo $?
> 1
> Peters-iMac:~ pd$ test -x `R RHOME`/bin/install ; echo $?
> 0

Yeah - true. I was already starting to wonder as I always was using ~R
CMD install~ and it always worked on my Mac.

Thanks again,

Rainer

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer at krugs.de

Skype:      RMkrug

PGP: 0x0F52F982
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 454 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20151029/a723b94f/attachment.bin>


More information about the R-devel mailing list