[R] lme: Can not find groupData object in a function could this be a scoping problem?

John Sorkin JSorkin at grecc.umaryland.edu
Sat Feb 14 00:00:08 CET 2015


R 3.1.0, RStudio  0.98.95
Windows 7


I have written a function that uses lme:


doit<- function(TS,rho,premean,presd,RxEffect) {
.
.
.
  # Prepare data frames for regression analyses.
  data <- data.frame(group=c(rep("Cont",SS),rep("Exp",SS)),
                   pre=pre,post=post)  
.
.
.
  previous<-data.frame(time=c("pre","post"),cbind(subject=i,group=data[i,"group"],t(data[i,c("pre","post")])))
. 

.
.
  inter<-groupedData(value~as.integer(time)+as.integer(group)+
                     as.integer(time)*as.integer(group)|subject,
                     inner=~group,data=previous)

  print(inter)
  lmeinter<-lme(inter)
.
.
.
}


When I run the code, at the statement,    lmeinter<-lme(inter)  I get a message:
Error in is.data.frame(data) : object 'inter' not found.
Please note that the print statement, print(inter) prints the groupedData object!
The code works fine when it is not in a function, i.e. 


  inter<-groupedData(value~as.integer(time)+as.integer(group)+
                     as.integer(time)*as.integer(group)|subject,
                     inner=~group,data=previous)

  lmeinter<-lme(inter)



runs and has no problem finding inter.


Can someone suggest what I might change to fix the problem? I think I may have a scoping problem but I am not knowledgeable enough to know (1) how to check this and (2) what to do to fix it.


Thanks,
John




John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing) 


Confidentiality Statement:
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. 


More information about the R-help mailing list