[R] Can I use a variable to pass a file name to scan() ?

From: Andrew Peterson <andrew_g_peterson_at_yahoo.com>
Date: Mon 28 Mar 2005 - 12:59:13 EST


Hi, can anyone please tell me if it is possible to use a variable to pass a file name to scan()?

I am trying to write a program that loops through a series of text files. I use list.files() to create a character vector of file names. Then I would like to take one string at a time from the character vector and use that string to specify the name of the text file I want to open using scan().

I have used constructs such as

x <- list.files()

y <- scan(file = x[1])

but I always get the following error message:

Error in scan(file = x[1]) : "scan" expected a real, got "<CLOSE>"

I've read all the documentation at least a couple of times and have searched this list to no avail. Any help would be greatly appreciated!

Thanks,

Andrew.



R-help@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 Received on Mon Mar 28 13:04:56 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:56 EST