[Rd] let R and Rscript infer paths from their own location (PR#14007)

pkensche at cmbi.ru.nl pkensche at cmbi.ru.nl
Thu Oct 15 15:40:21 CEST 2009


Full_Name: Philip R. Kensche
Version: 2.9.1
OS: Linux
Submission from: (NULL) (131.174.146.252)


Use case:
Run R scripts using bin/Rscript or "bin/R --no-restore --file=<script-file>
--args <args>" in a heterogeneous computing grid in which it is not possible to
predict the actual installation directory of the R binaries.

Problem:
The script bin/R and the wrapper bin/Rscript contain hardcoded paths. Thus,
currently, it is not possible to install R in a local directory tree, install
packages and finally run this installation on a heterogeneous computing grid.
The configure option --disable-rpath doesn't have any influence on whether
hardcoded paths are used in these programs.

Proposed solution:
Let bin/R and bin/Rscript infer their own positions using something like
$(dirname $(readlink -f "$0")) (for bin/R) and set the other paths (such as
R_HOME_DIR in bin/R) relative to these.

The start of bin/R could look something like this:

----
if test -z "${R_HOME_DIR}"; then
    R_HOME_DIR=$(dirname $(readlink -f "$0"))/../lib/R
fi

case "linux-gnu" in
    linux*)
    run_arch=`uname -m`
    case "$run_arch" in
        x86_64|mips64|ppc64|powerpc64|sparc64|s390x)
        libnn=lib64
        libnn_fallback=lib
        ;;
        *)
        libnn=lib
        libnn_fallback=lib64
        ;;
    esac
    if [ -x "${R_HOME_DIR}/../../${libnn}/R/bin/exec/R" ]; then
        R_HOME_DIR="${R_HOME_DIR}/../../${libnn}/R"
    elif [ -x "${R_HOME_DIR}/../../${libnn_fallback}/R/bin/exec/R" ]; then
        R_HOME_DIR="${R_HOME_DIR}/../../${libnn_fallback}/R"
    ## else -- leave alone (might be a sub-arch)
    fi
    ;;
esac


if test -n "${R_HOME}" && \
    test "${R_HOME}" != "${R_HOME_DIR}"; then
    echo "WARNING: ignoring environment value of R_HOME"
fi
R_HOME="${R_HOME_DIR}"
export R_HOME
R_SHARE_DIR="${R_HOME}/share"
export R_SHARE_DIR
R_INCLUDE_DIR="${R_HOME}/include"
export R_INCLUDE_DIR
R_DOC_DIR="${R_HOME}/doc"
export R_DOC_DIR

...
----

There are some things that I don't understand about the original script, though.
Why does it start with a test that always succeeds? Why does it ignore R_HOME? I
didn't change this stuff. In any case, the changes above did the job for me.

Greetings,

Philip



More information about the R-devel mailing list