rrandomrevolution-r

random selection on XDF


I have tried a lot of alternatives, including the one we can find on Revo website

xform <- function(data) { 
    data$.rxRowSelection <- as.logical(rbinom(nr, 1 , 0.5))
    return(data)
}
rxDataStep(inData = "two_vars.xdf", outFile = "testSample",
           transformFunc = xform , overwrite = TRUE)

when nr is info$numRows from rxGetInfo("two_vars.xdf")

rxDataStep(inData = "two_vars.xdf", outFile = "testSample",
           rowSelection = as.logical(rbinom(nr, 1, 0.5)), overwrite = TRUE)

ERROR: The sample data set for the analysis has no variables. Error in doTryCatch(return(expr), name, parentenv, handler) : std::exception

thanks for helping !


Solution

  • Try this:

    xform <- function(data) { 
        data$.rxRowSelection <- as.logical(rbinom(.rxNumRows, 1 , 0.5))
        return(data)
    }
    rxDataStep(inData = "two_vars.xdf", outFile = "testSample",
               transformFunc = xform , overwrite = TRUE)
    

    Or equivalently:

    rxDataStep(inData = "two_vars.xdf", outFile = "testSample",
               rowSelection = as.logical(rbinom(.rxNumRows, 1 , 0.5)), 
               overwrite = TRUE)
    

    I think there were two issues with what you were doing.

    1. You were passing total number of rows and you would need number of rows in that particular chunk. (not the cause of your current error)
    2. You need to pass objects via transformObjects into the transform environment to use them.