Operating on date class variables

I can’t find anything for working with date and timestamp data classes. I need to analyse a numeric variable for a subset of the data in which the date is between two values. I’ve tried to create a subset with:

ds.dataFrameSubset(df.name = 'D', V1.name = 'D$DATE', Boolean.operator = '<=', V2.name = '2019-01-31', newobj = 'JAN19')

But this is “invalid in at least one source” and “there are studysideMessage(s) on this datasource”, I don’t have any more info in these studysideMessages (I should note that D$DATE is class Date and ranges from 2019-01-01 to 2020-06-30). Any idea on how to approach with this?

I found a solution if anyone is interested: log into the Opal servers via your browser and go to ‘Administration’, then ‘DataSHIELD’, under ‘Methods’ select ‘Assign’, click ‘Add Method’ and add base::substring to the listed methods; you’ll need to do this on each server; in you R environment use

ds.asCharacter(x.name = "D$DATE", newobj = "chardate")

ds.assign(toAssign = "as.numeric(substring(chardate, 1, 4))", newobj = 'YEAR')

ds.assign(toAssign = "as.numeric(substring(chardate, 6, 7))", newobj = 'MONTH')

ds.cbind(x = c("D", "YEAR", "MONTH"), newobj = "D1")

ds.dataFrameSubset(df.name = "D1", V1.name = "D1$YEAR", Boolean.operator = "==", V2.name = "2020", newobj = "D2020")

ds.dataFrameSubset(df.name = "D2020", V1.name = "D2020$MONTH", Boolean.operator = "==", V2.name = "1", newobj = "DJAN2020")

Hi Jack,

Yes, that is the solution, however I want to note that the DataSHIELD users do not have the rights to add any methods using your suggested way. Only the people who have admin rights (e.g. data managers) can change/add something on the server-side. :slight_smile:

1 Like