I tried to make the following function: function(x, y){ dates<-intersect(x[,1],y[,1]) m<-matrix(NA,length(dates),3) m[,1]<-dates j<-1 k<-1 for(i in fdax[,1]){ if(is.element(i,dates)){ m[j,3]<-as.numeric(fdax[k,2]) j<-j+1 } k<-k+1 } return(m) } When I try to import it into R with edit( file="name.txt", editor="someeditor") I get the response that there is an error on the line where last bracket is. When I execute this code manualy in R command by command everything works ok. This happened to me before with other functions. Sometimes I can import them and they work perfectly but sometimes I get the error on the last line of code which is alvays the final bracket. Anyone has any idea why this is happening?
"Ivan Kalafatic" <ivan.kalafatic at gmail.com> writes:> I tried to make the following function: > > function(x, y){ > dates<-intersect(x[,1],y[,1]) > m<-matrix(NA,length(dates),3) > m[,1]<-dates > j<-1 > k<-1 > for(i in fdax[,1]){ > if(is.element(i,dates)){ > m[j,3]<-as.numeric(fdax[k,2]) > j<-j+1 > } > k<-k+1 > } > return(m) > } > > When I try to import it into R with edit( file="name.txt", > editor="someeditor") I get the response that there is an error on the > line where last bracket is. > When I execute this code manualy in R command by command everything works ok. > This happened to me before with other functions. Sometimes I can > import them and they work perfectly but sometimes I get the error on > the last line of code which is alvays the final bracket. > > Anyone has any idea why this is happening?It's not happening for me with> edit( file="tmp/xxx.R", editor="emacs")function(x, y){ dates<-intersect(x[,1],y[,1]) m<-matrix(NA,length(dates),3) m[,1]<-dates j<-1 k<-1 for(i in fdax[,1]){ if(is.element(i,dates)){ m[j,3]<-as.numeric(fdax[k,2]) j<-j+1 } k<-k+1 } return(m) } (after copying your function into tmp/xxx.R of course). So there is something you're not telling us... (could there be an incomplete last line, by any chance?) -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Try to insert a space before the last bracket! R sometimes does not accept a curly bracket as a first character on a line of a script. Regards, Valentin --- Ivan Kalafatic <ivan.kalafatic at gmail.com> wrote:> I tried to make the following function: > > function(x, y){ > dates<-intersect(x[,1],y[,1]) > m<-matrix(NA,length(dates),3) > m[,1]<-dates > j<-1 > k<-1 > for(i in fdax[,1]){ > if(is.element(i,dates)){ > m[j,3]<-as.numeric(fdax[k,2]) > j<-j+1 > } > k<-k+1 > } > return(m) > } > > When I try to import it into R with edit( > file="name.txt", > editor="someeditor") I get the response that there > is an error on the > line where last bracket is. > When I execute this code manualy in R command by > command everything works ok. > This happened to me before with other functions. > Sometimes I can > import them and they work perfectly but sometimes I > get the error on > the last line of code which is alvays the final > bracket. > > Anyone has any idea why this is happening? > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code. >
Ivan Kalafatic wrote:> I tried to make the following function: > > function(x, y){ > dates<-intersect(x[,1],y[,1]) > m<-matrix(NA,length(dates),3) > m[,1]<-dates > j<-1 > k<-1 > for(i in fdax[,1]){ > if(is.element(i,dates)){ > m[j,3]<-as.numeric(fdax[k,2]) > j<-j+1 > } > k<-k+1 > } > return(m) > } > > When I try to import it into R with edit( file="name.txt", > editor="someeditor") I get the response that there is an error on the > line where last bracket is. > When I execute this code manualy in R command by command everything works ok. > This happened to me before with other functions. Sometimes I can > import them and they work perfectly but sometimes I get the error on > the last line of code which is alvays the final bracket. > > Anyone has any idea why this is happening?Hi Ivan, The only thing I can see is that you haven't assigned the function to a name. That is, I would usually start with: my.date.function<-function(... I don't know where this might cause a problem, but see if it makes a difference. Jim
Maybe Matching Threads
- Creating regularly spaced time series from irregular one
- Convert ordinary dates into POSIX
- Help with selecting data from irregular time series {its} objects
- [FORGED] Re: Plotmath on Fedora 31 broken with with pango >= 1.44 - workarounds?
- T100p half-height PCI bracket