Current user lubomir pavliska  2022-04-27 13:03
Status: Active
 

Hello.

How can I get the name of current user (current logged) in R Report? I need it for identification rows in excel file exported from R report.
I tried it via
res=GET("http://vav.fno.cz/login-whoAmI.api")
prettify(rawToChar(res$content))

but no working, empty content.

Thanks

Lubomir

 
 
mohara responded:  2022-05-02 09:21

Hi Lubomir:

There are a couple of ways to get the current logged in user in a LabKey R report.

  1. There is an implicit variable "labkey.user.email" that will return the email address of any user. This and other substitutions are listed on the Help tab in the R report builder, and in the documentation here.
    --
    print(labkey.user.email)

  2. You can use the Rlabkey package which includes "labkey.whoami" that will return the display name (or user ID) if you prefer that. You can also use the substitution token "labkey.url.base" to provide the URL for you. Documentation for Rlabkey is on CRAN here.
    --
    library(Rlabkey)
    user <- labkey.whoAmI(labkey.url.base)
    print(user$id)
    print(user$displayName)

Hopefully one of these will meet your needs,

--Molly