A full dataset or any portion of a dataset can be downloaded into an R data frame using the
labkey.selectRows
function. Function arguments are the components of the url that identify
the location of the data and what actions should be taken on the data prior to import
(ie, sorting, selecting particular columns or maximum number of rows, etc.).
Stored queries in LabKey Server have an associated default view and may have one or more named views. Views determine the column set of
the return data frame. View columns can be a subset or superset of the columns of the underlying query (a subset if columns from the
query are left out of the view, and a superset if lookup columns in the underlying query are used to include columns from related queries).
Views can also include filter and sort properties that will make their result set different from the underlying query.
If no view is specified, the columns and rows returned are determined by the default view, which may not be the same as the
result rows of the underlying query. Please see the topic on Saving Views in the LabKey online documentation.
In the returned data frame, there are three different ways to have the columns named:
colNameOpt='caption'
uses the caption value, and is the default option for backward compatibility.
It may be the best option for displaying to another user, but may make scripting more difficult.
colNameOpt='fieldname'
uses the field name value, so that the data frame colnames are the same names
that are used as arguments to labkey function calls. It is the default for the new getRows
session-based
function.
colNameOpt='rname'
transforms the field name value into valid R names by substituting an underscore for both
spaces and forward slash (/) characters and lower casing the entire name. This option is the way a data frame is passed to a
script running in a LabKey server in the R View feature of the data grid. If you are writing scripts for running in an
R view on the server, or if you prefer to work with legal r names in the returned grid, this option may be useful.
For backward compatibility, column names returned by labkey.executeSql
and labkey.selectRows
are field captions by default. The getRows
function has the same
colNameOpt parameter but defaults to field names instead of captions.