Learn R Programming

Rlabkey (version 2.1.121)

getSession: Creates and returns a LabKey Server session

Description

The session object holds server address and folder context for a user working with LabKey Server. The session-based model supports more efficient interactive use of LabKey Server from R.

Usage

getSession(baseUrl, folderPath="/home", curlOptions=NULL, lkOptions=NULL)

Arguments

baseUrl
a string specifying the address of the LabKey Server, including the context root
folderPath
a string specifying the hierarchy of folders to the current folder (container) for the operation, starting with the project folder
curlOptions
(optional) a list of curlOptions to be set on connections to the LabKey Server, see details
lkOptions
(optional) a list of settings for default behavior on naming of objects, see details

Value

  • getSession returns a session object that represents a specific user within a specific project folder within the LabKey Server identified by the baseUrl. The combination of user, server and project/folder determines the security context of the client program. See the Rlabkey Users Guide for more discussion of how the user identity is established.

Details

Creates a session key that is passed to all the other session-based functions. Associated with the key are a baseUrl and a folderPath which determine the security context.

curlOptions

The curlOptions parameter gives a mechanism to pass control options down to the RCurl library used by Rlabkey. This can be very useful for debugging problems or setting proxy server properties. See exammple for debugging.

lkOptions

The lkOptions parameter gives a mechanism to change default behavior in the objects returned by Rlabkey. Currently the only available options are colNameOpt, which affects the names of columns in the data frames returned by getRows(), and maxRows, which sets a default value for this parameter when calling getRows()

See Also

getRows, getSchema, getLookups saveResults The Rlabkey Users Guide is available by typing RlabkeyUsersGuide().

Examples

Run this code
# library(Rlabkey)
s<-getSession(baseUrl="http://localhost:8080/labkey", folderPath="/apisamples")
s   #shows schemas

scobj <- getSchema(s, "lists")
scobj    #shows available queries

scobj$AllTypes   #this is the query object

lkdata<- getRows(s, scobj$AllTypes)   #shorthand for labkey.selectRows, all the same args apply
lkdata

lucols <- getLookups(s, scobj$AllTypes$Category)   #can add fields from related queries
lucols

lucols2 <- getLookups(s, lucols[["Category/Group"]])  # keep going to other tables

cols <- c(names(scobj$AllTypes)[2:6], names(lucols)[2:4])

getRows(s, scobj$AllTypes, colSelect=paste(cols, sep=","))
	
## using lkOptions
## change the default column naming to be the same as used in the default labkey.data data frame in R views
## with rname, spaces and slashes are replace with underscores, and the whole name is lower cased

lkOptions<-list("colNameOpt"="rname")
srname <-getSession(baseUrl="http://localhost:8080/labkey", folderPath="/apisamples", lkOptions=lkOptions)
getRows(srname, scobj$AllTypes)

## using the curlOptions for generating debug tracesof network traffic
d<- debugGatherer()
copt <- curlOptions(debugfunction=d$update, verbose=TRUE, cookiefile='/cooks.txt')
sdbg<- getSession(baseUrl="http://localhost:8080/labkey", folderPath="/apisamples", 
	 curlOptions=copt)
getRows(sdbg, scobj$AllTypes)
strwrap(d$value(), 100)

Run the code above in your browser using DataLab