Skip to content

character vector as input to function?

4 messages · Bill Simpson, Ben Bolker, Nicholas Lee

#
I would like to have a function that inputs a file name, then reads that
data file and does various stuff to it.
Something like:

doit<-function(filename)        
{
x<-scan("~/rstuff/data/"filename)
#for example, if filename is a0.dat, it will scan("~/rstuff/data/a0.dat")  
...
}

Can someone please tell me how to do this?

Thanks for any help!

Bill Simpson

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Thanks very much for the help, Ben.

Bill

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Well, somebody else will probably respond, but for example:

paca:ben> cat >~/R/test
1 2 3 4
+    path <- "~/R/"  
+    x <- scan(paste(path,filename,sep=""))
+    mean(x)
+ }
Read 4 items
[1] 2.5
On Wed, 14 Apr 1999, Bill Simpson wrote:

            
Benjamin Bolker          Dep't of Ecology and Evolutionary Biology,
ben at eno.princeton.edu    Princeton University
tel: (609) 258-6886,     fax: (609) 258-1334

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Wed, 14 Apr 1999, Bill Simpson wrote:

            
Try:
[1] "~/rstuff/data/a0.dat"
 
Nicholas


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._