Set Up Steps:
Additional Steps for Linux/OSX:
Once an administrator has set up the R environment, your users can create R Reports
- On the R site, choose a CRAN mirror near you.
- Click Download for the OS you are using (Linux, OSX, or Windows).
- Click the subcategory base.
- Download the installer using the link provided, for example Download R 3.4.1 for Windows.
- Install using the downloaded file.
- You don’t need to download the “contrib” folder on the Install site. It’s easy to obtain additional R packages individually from within R.
- Details of R installation/admin can be found here.
- Linux. An example of installing R on Linux is included on the Configure R on Linux page.
- Windows. On Windows, install R in a directory whose path does not include a space character. The R FAQ warns to avoid spaces if you are building packages from sources.
Configure LabKey Server to Work with R
Configure Authentication and PermissionsAuthentication.
If you wish to modify a password-protected LabKey Server database through the Rlabkey macros
, you will need to set up authentication. See: Create a netrc file
Refer to Configure Permissions
for information on how to adjust the permissions necessary to create and edit R Views. Note that only users who are part of the "Developers" site group or have Site Admin permissions can edit R Views.Batch Mode.
Scripts are executed in batch mode, so a new instance of R is started up each time a script is executed. The instance of R is run using the same privileges as the LabKey Server, so care must be taken to ensure that security settings (see above) are set accordingly. Packages must be re-loaded at the start of every script because each script is run in a new instance of R.
Install & Load Additional R Packages
You will likely need additional packages to flesh out functionality that basic install does not include. Additional details on CRAN packages are available here
. Packages only need to be installed
once on your LabKey Server. However, they will need to be loaded
at the start of every script when running in batch mode.How to Install R Packages
Use the R command line or a script (including a LabKey R script) to install packages. For example, use the following to install two useful packages, "GDD" and "Cairo":
install.packages(c("GDD", "Cairo"), repos="http://cran.r-project.org" )
To install knitr:
You can also use the R GUI (Packages > Install Packages
) to select and install packages.How to Load
Each package needs to be installed AND loaded. If the installed package is not set up as part of your native R environment (check ‘R_HOME/site-library’), it needs to be loaded every time you start an R session. Typically, when running R from the LabKey interface, you will need to load (but not install) packages at the start of every script because each script is run in a new instance of R.
To load an installed package (e.g., Cairo), call:Recommended PackagesGDD &/or Cairo
: If R runs on a headless Linux server, you will likely need at least one extra graphics package. When LabKey R runs on a headless Linux server, it may not have access to the X11 device drivers (and thus fonts) required by the basic graphics functions jpeg() and png(). Installing the Cairo and/or GDD packages will allow your users to output .jpeg and .png formats without using the jpeg() and png() functions. More details on these packages are provided on the Determine Available Graphing Functions
You can avoid the use of Cairo and/or GDD by installing a display buffer for your headless server (see below for more info).Lattice
: Optional. This package is the commonly used, sophisticated graphing package for R. It is particularly useful for creating Participant Charts
Headless Linux Servers Only: Install the X Virtual Frame Buffer
On Linux servers, the png() and jpg() functions use the device drivers provided by the X-windows display system to do rendering. This is a problem on a headless server where there is generally no display running at all.
As a workaround, you can install the X Virtual Frame Buffer. This allows applications to connect to an X Windows server that renders to memory rather than a display.
For instructions on how to install and configure the X Virtual Frame Buffer on Linux, see Configure the Virtual Frame Buffer on Linux
If you do not install the X Virtual Frame Buffer, your users may need to use graphics packages such as GDD or Cairo to replace the png() and jpeg() functions. See Determine Available Graphing Functions
for further details.
OSX Only: Fix Hostname Resolution Problems
When a LabKey Server runs on OSX, R views can only resolve hostnames that are stored in the server's host file.
It appears that OSX security policy blocks spawned processes from accessing the name service daemon for the operating system.
You can use one of two work-arounds for this problem:
- Add the hostname (e.g., www.labkey.org) to the hosts file (/etc/hosts). Testing has shown that the spawned process is able to resolve hostnames that are in the host file.
- Use the name "localhost" instead of DNS name in the R script.