Set Up Steps: Additional Steps for Unix/MacOSX: Once an administrator has set up the R environment, your users can create R Reports.

Install R

  • On the R site, choose a CRAN mirror near you.
  • Click Download for the OS you are using (Linux, MacOSX, or Windows).
  • Click the subcategory base.
  • Download the installer using the link provided, for example Download R 3.1.3 for Windows.
  • Install using the downloaded file.

Tips:

  • 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.
OS-Specific Instructions:
  • 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 Permissions

Authentication. 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 or _netrc file.

Permissions. 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:

install.packages('knitr', dependencies=TRUE)

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:

library(Cairo)

Recommended Packages

GDD &/or Cairo: If R runs on a headless Unix server, you will likely need at least one extra graphics package. When LabKey R runs on a headless Unix 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 page.

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 Unix Servers Only: Install the X Virtual Frame Buffer

On Unix 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.

MacOSX Only: Fix Hostname Resolution Problems

When a LabKey Server runs on MacOSX, R views can only resolve hostnames that are stored in the server's host file.

It appears that MacOSX 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:

  1. 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.
  2. Use the name "localhost" instead of DNS name in the your R script.

Related Topics

Discussion

previousnext
 
expand all collapse all