renvironment-variablescentos7opencpurapache

User-defined environment variables are missing in OpenCPU


I defined some environment variables on CentOs and they are visible from R shell.

]$ sudo R -e 'Sys.getenv()'

AMAZONREDSHIFTODBCINI   /etc/amazon.redshiftodbc.ini
ODBCINI                 /etc/odbc.ini
ODBCSYSINI              /usr/local/odbc
LD_PRELOAD              /usr/local/lib/libodbcinst.so
.
.
.

Unfortunately, these variables are not visible from OpenCpu. If I call Sys.getenv() from OpenCpu, I get the below result:

## EDITOR                vi
## HOME                  /tmp/ocpu-temp
## LANG                  en_US.UTF-8
## LN_S                  ln -s
## MAKE                  make
## NOTIFY_SOCKET         /run/systemd/notify
## PAGER                 /usr/bin/less
## PATH                  /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
## R_BROWSER             /usr/bin/xdg-open
## R_BZIPCMD             /usr/bin/bzip2
## R_GZIPCMD             /usr/bin/gzip
## R_HOME                /usr/lib64/R
## R_LIBS_SITE           /usr/local/lib/R/site-library:/usr/local/lib/R/library:/usr/lib64/R/library:/usr/share/R/library
## R_LIBS_USER           ~/R/x86_64-redhat-linux-gnu-library/3.4
## R_PAPERSIZE           a4
## R_PDFVIEWER           /usr/bin/xdg-open
## R_PLATFORM            x86_64-redhat-linux-gnu
## R_PRINTCMD            lpr
## R_RD4PDF              times,hyper
## R_SESSION_TMPDIR      /tmp
## R_SYSTEM_ABI          linux,gcc,gxx,gfortran,?
## R_TEXI2DVICMD         /usr/bin/texi2dvi
## R_UNZIPCMD            /usr/bin/unzip
## R_ZIPCMD              /usr/bin/zip
## SED                   /usr/bin/sed
## TAR                   /usr/bin/gtar
## TMPDIR                /tmp/ocpu-temp

This is a blocker, so any ideas will be greatly appreciated. Thanks...


Solution

  • You can define custom variables in /etc/opencpu/Renviron on the server. Alternatively you can create a script in /etc/opencpu/Rprofile in which you use Sys.setenv() to set the vars.