scope - R 'object XX not found' error thrown inside function, but not in script -


i new r, apologies if question bit silly.

i calling function in external package ('mmlcr', although don't think directly relevant problem), , 1 of required inputs (data) data.frame. compose data.frame various data using following approach (simplified illustration):

    #id, time, , value vectors created elsewhere in code.     mydata = data.frame(a=id, b=time, c=value)       out <- mmlcr( input1, input2, data=mydata, input4) 

which throws error:

error in is.data.frame(data) : object 'mydata' not found 

the debugger indicates error thrown during mmlcr() call.

i added print(ls()) prior mmlcr() call, , output confirmed "mydata" in function workspace; further is.data.frame(mydata) returned true. seems "mydata" being created, reason not passing mmlcr() function properly. (commenting line causes no error thrown, i'm pretty sure problematic line).

however, when put exact same code in script (i.e., not within function block), no such error thrown , output expected. thus, assume there scoping issue arises.

i have tried both assignment approaches:

mydata = data.frame(a=id, b=time, c=value)   mydata <- data.frame(a=id, b=time, c=value)   

and both give me same error. admit don't understand scope model in r (i've read differences between = , <- , think it, i'm not sure).

any advice can offer appreciated.

mmlcr deprecated , should search alternatives. without looking it, sleuthed through old repo , found culprit:

m <- eval(m, data) 

in function mmlcr.default. there lot of reasons why bad, scoping big one. r has issue subset.data.frame function, see old question. rather modify source code, find way function subroutine using for, repeat, or while loop.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -