edwindj / ffbase

Basic (statistical) functionality for R package ff
github.com/edwindj/ffbase/wiki
35 stars 15 forks source link

Problem when using subset.ffdf whithin a function #58

Open carlosavellaneda8 opened 4 years ago

carlosavellaneda8 commented 4 years ago

Hi,

I am having some troubles trying to use subset whithin a function. I need a function that receives a string as an argument to make a subset, and it works fine when the object is a data frame but fails when the object is an ffdf. Here is a minimal example:

df <- mtcars
df_ffdf <- as.ffdf(df)

df_subset <- function(df, subset_string){
  subset(df, eval(parse(text = subset_string)))
}
tmp <- df_subset(df, 'mpg >= 20')
tmp2 <- df_subset(df_ffdf, 'mpg >= 20')

The error I get is object 'mpg' not found. I would appreciate any hints to solve this problem. Thanks in advance.

Best regards, Carlos

edwindj commented 4 years ago

Dear Carlos,

Thanks for reporting! Strange error which I will look into. A quick fix is the following:

library(ffbase) df <- mtcars df_ffdf <- as.ffdf(df)

df_subset <- function(df, subset_string){ subset(df, eval(parse(text = subset_string))) }

df_subset <- function(df, subset_string){ e <- parse(text = subset_string) eval(substitute(subset(df, e))) }

tmp <- df_subset(df, 'mpg >= 20') tmp2 <- df_subset(df_ffdf, "mpg >= 20")

Best,

Edwin

Op ma 17 feb. 2020 om 16:22 schreef carlosavellaneda8 < notifications@github.com>:

Hi,

I am having some troubles trying to use subset whithin a function. I need a function that receives a string as an argument to make a subset, and it works fine when the object is a data frame but fails when the object is an ffdf. Here is a minimal example:

df <- mtcars df_ffdf <- as.ffdf(df)

df_subset <- function(df, subset_string){ subset(df, eval(parse(text = subset_string))) } tmp <- df_subset(df, 'mpg >= 20') tmp2 <- df_subset(df_ffdf, 'mpg >= 20')

The error I get is object 'mpg' not found. I would appreciate any hints to solve this problem. Thanks in advance.

Best regards, Carlos

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/edwindj/ffbase/issues/58?email_source=notifications&email_token=AAEEOHFT67UVA52BUFYR3ZTRDKTRZA5CNFSM4KWTW6L2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IOCCZOA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEEOHHUP2MBSYQGQO5GG6DRDKTRZANCNFSM4KWTW6LQ .