Working with Logicals

Hi all,

I am trying to wrap my head around how DataShield handles Logical variables. For example, ds.table coerces a Logical to Factor implicitly. Yet the Data Presentation functions, don’t. ds.boxPlot reports an error if a Logical is passed instead of a Factor.

Does one have to use ds.asFactor here? If so, how?

Hi @aakkoc

Yes many functions do not work with logical variables, so it is better if you convert a logical to a factor. I guess with a box plot you mean to show the distribution of a numeric variable for TRUE/FALSE cases of a logical variable, is that right?

If yes, then look how you can do it in this example:

builder <- DSI::newDSLoginBuilder()
builder$append(server = "study1", url = "", user = "administrator", password = "password", table = 'TESTING.TESTING1', driver = "OpalDriver", options='list(ssl_verifyhost=0, ssl_verifypeer=0)')

logindata <- builder$build()

connections <- datashield.login(logins = logindata, assign = TRUE, symbol = "D")

ds.boxPlot(x = 'D$NUMERIC', type='split')

ds.asFactor("D$LOGICAL", = 'logical.f')

ds.dataFrame(c('D', 'logical.f'), newobj='D')

ds.boxPlot(x = 'D', variables = 'NUMERIC', group = 'logical.f', type='split')

Thanks, Demetris

1 Like