Accessing multiple queries in R View

LabKey Support Forum (Inactive)
Accessing multiple queries in R View laurapas  2016-01-14 17:02
Status: Closed
 
Hi,
I am able to access the labkey.data as the data that I've chosen to base my R View on, but what if I need to access multiple queries (custom list, another custom SQL query, etc...) within the R script? I thought to use labkey.selectRows, but getting an error (See below). I can access fine outside LabKey, but not successful within LabKey. Is there a better way to access multiple data tables? Or I am doing something wrong?


# Get peptide reference
peptideref <- labkey.selectRows(
  baseUrl="https://labkey-dev.roche.com:8443/labkey",
  folderPath="/gRED/results",
  schemaName="lists",
  queryName="peptidereference",
  viewName="",
  colNameOpt = "fieldname",
  containerFilter=NULL
)
############

Error in function (type, msg, asError = TRUE) :
  Unknown SSL protocol error in connection to labkey-dev.roche.com:8443
Calls: labkey.selectRows ... getURI -> curlPerform -> .Call -> <Anonymous> -> fun
Execution halted
 
 
Jon (LabKey DevOps) responded:  2016-01-15 00:29
Hi Laura,

The R script looks fine.

The error in question though looks like you might either be on an older version of R or an older version of Rlabkey. I know that some changes to SSL compatibility have occurred with R in the last six months (https://cran.r-project.org/web/packages/Rlabkey/NEWS), so upgrading might be required here.

Currently, R is on version 3.2.3 (https://cran.r-project.org/) and Rlabkey is on 2.1.129 (https://cran.r-project.org/web/packages/Rlabkey/index.html)

Can you confirm your version of R and Rlabkey is current?

Regards,

Jon
 
laurapas responded:  2016-01-15 10:59
Hi Jon,
It looks like we are using older versions. See below.

Is this the only way to access multiple SQL tables within an R View inside LabKey? I can only access one table directly (i.e., labkey.data), but need to use the Rlabkey package to access additional tables within the same script?

  Console output
Loading required package: RCurl
Loading required package: bitops
Loading required package: rjson
R version 3.1.2 (2014-10-31)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] Rlabkey_2.1.125 rjson_0.2.15 RCurl_1.95-4.5 bitops_1.0-6
               _
platform i386-w64-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 3
minor 1.2
year 2014
month 10
day 31
svn rev 66913
language R
version.string R version 3.1.2 (2014-10-31)
nickname Pumpkin Helmet
> proc.time()
   user system elapsed
   1.07 0.03 1.12
 
Jon (LabKey DevOps) responded:  2016-01-15 22:07
Hi Laura,

My mistake, I had thought you were running these queries in a standalone version of R rather than within the R View Builder.

So I was able to run a similarly designed query within a newly created R view like this:

########################
# This sample code returns the query data in tab-separated values format, which LabKey then
# renders as HTML. Replace this code with your R script. See the Help tab for more details.
write.table(labkey.data, file = "${tsvout:tsvfile}", sep = "\t", qmethod = "double", col.names=NA)

library(Rlabkey)
# Select rows into a data frame called 'mydata'

mydata <- labkey.selectRows(
    baseUrl="https://www.labkey.org",
    folderPath="/Support Tickets/Dashboards/JonY",
    schemaName="lists",
    queryName="ListTest2",
    viewName="",
    colFilter=NULL,
    containerFilter=NULL
)

write.table(mydata, file = "${tsvout:tsvfile}", sep = "\t", qmethod = "double", col.names=NA)

########################

For the second query to work, I had to have library(Rlabkey) being called within it. But that along with the write.table() function allowed my existing table from "labkey.data" and my other table as "mydata" appeared on the view tab successfully.

Also, the version of R on the server I tested this against is on the latest version with the latest version of Rlabkey as well.

I would recommend upgrading your version of R and upgrade your Rlabkey package on the server, then giving the query another try and making sure you load the Rlabkey library within your script.

Give this a try and let us know how it goes.

Regards,

Jon
 
laurapas responded:  2016-02-10 11:32
Hi Jon,

R installation and packages were updated, but it's still not working within a LabKey R view.

library(Rlabkey)

peptideref <- labkey.selectRows(
  baseUrl="https://labkey-dev.roche.com:8443/labkey",
  folderPath="/gRED/QuaSAR Dev 2/QuaSAR Dev 2 results",
  schemaName="lists",
  queryName="peptidereference",
  viewName="",
  colNameOpt = "fieldname",
  containerFilter=NULL
)

str(peptideref)


Here's what we get in the View tab:

javax.script.ScriptException: javax.script.ScriptException: An error occurred when running the script 'script.R', exit code: 1).
Loading required package: RCurl
Loading required package: bitops
Loading required package: rjson
Error in function (type, msg, asError = TRUE) :
  SSL certificate problem: unable to get local issuer certificate
Calls: labkey.selectRows ... getURI -> curlPerform -> .Call -> <Anonymous> -> fun
Execution halted
 
Jon (LabKey DevOps) responded:  2016-02-10 11:55
Hi Laura,

Is this the same computer that is having problems with running this selectRows as this one?

https://www.labkey.org/home/Developer/Forum/announcements-thread.view?rowId=12302

Or is this a different computer?

Regards,

Jon
 
laurapas responded:  2016-02-10 12:00
Hi Jon,
No this is on the LabKey server. The other ticket is on the Mac. For the other ticket, I had to transfer the code to my Mac because it's not working on the server, even with the same package versions.
 
Jon (LabKey DevOps) responded:  2016-02-10 15:12
Hi Laura,

Thanks for upgrading the components and confirming this for us.

I'm wondering whether the SSL configuration is being rejected outright due to it not being configured correctly or possibly being a bad or expired certificate on the server itself.

Can you verify if the certificate that is local on the server is valid?

Regards,

Jon
 
Jon (LabKey DevOps) responded:  2016-02-12 13:13
Hi Laura,

We were able to determine that the problem is with the SSL certificate on the dev server and it will need to be updated.

I'm going to be coordinating with a Michel and Nacho to get this resolved.

Regards,

Jon