I have a function where I'm reading an xdf file using rxXdfToDataFrame and using a variable in my expression for rowSelection. If I don't pass transformEnvir=environment()
, the variable is not found. My problem is that after calling the function with transformEnvir
, I can't seem to reliably access .GlobalEnv
. If I hardcode a number into rowSelection
I don't need to use transformEnvir
and everything works correctly. I tried setting the environment, but I'm not sure I was even doing it correctly.
The following code reproduces my problem:
envirtest = function()
{
require(data.table)
df = data.frame(x=1:10)
selectnum = 5
rxDataFrameToXdf(df, "testxdf.xdf")
testdf = rxXdfToDataFrame("testxdf.xdf",rowSelection=(x==selectnum),transformEnvir=environment())
testdt = setDT(testdf)
}
The error that occurs:
Error in envirtest() : could not find function "setDT"
However, if instead of setDT()
, data.table::setDT()
is used, then the function executes.
edit: I forgot to mention that I had tried it without transformEnvir
set and everything worked properly. Also, tables() was changed to setDT() to avoid possible confusion.