labkey.setDefaults: Set the default parameters used for all http or https...

View source: R/labkey.defaults.R

labkey.setDefaultsR Documentation

Set the default parameters used for all http or https requests


Use this function to set the default baseUrl and authentication parameters as package environment variables to be used for all http or https requests. You can also use labkey.setDefaults() without any parameters to reset/clear these settings.


labkey.setDefaults(apiKey="", baseUrl="", email="", password="")



session key from your server


server location including context path, if any. e.g.


user email address


user password


Note: Support for API keys was added in LabKey Server release 16.2; they are not supported in 16.1 or earlier.

An API key can be used to authorize Rlabkey functions that access protected content on LabKey Server. Using an API key avoids copying and storing credentials on the client machine. Also, all Rlabkey access is tied to the current browser session, which means the code runs in the same context as the browser (e.g. same user, same authorizations, same declared terms of use and PHI level, same impersonation state, etc.).

A site administrator must first enable the use of API keys on that LabKey Server. Once enabled, any logged in user can generate an API key by clicking their display name (upper right) and selecting "API Keys". The API Key page creates and displays keys that can be copied and pasted into a labkey.setDefaults() statement to tie an Rlabkey session to the authorization and session information already set in the browser.

If an API key is not provided, you can also use this function for basic authentication via email and password. Note that both email and password must be set via a labkey.setDefaults() call. If an apiKey is also set, that will be given preference and the email/password will not be used for authentication. Once authenticated via email/password, you can make multiple labkey.get or API calls using that same connection.


## Example of setting and clearing an API key and/or email/password.
# library(Rlabkey)

labkey.setDefaults(email="testing@localhost.test", password="password")

## Functions invoked at this point share authorization
## and session information with the browser session

labkey.setDefaults() # called without any parameters will reset/clear the environment variables

Rlabkey documentation built on April 1, 2022, 5:07 p.m.