Re: [R] Store filename

From: jim holtman <jholtman_at_gmail.com>
Date: Mon, 09 Jun 2008 10:22:55 -0400

list.files() will return the files in your current directory and you can use that in a 'for' statement to loop through processing:

for (fileName in list.files()){

    input <- read.table(fileName,....)
    ....
}

On Mon, Jun 9, 2008 at 10:07 AM, DAVID ARTETA GARCIA < darteta001_at_ikasle.ehu.es> wrote:

> Hi Henrique, Daniel and Jim, and rest of the list. Your comments have been
> really useful. Daniel, you mention whether I am looping over some files
> stored in a directory. Is that actually doable with R? I mean, is it
> possible to read all the files in the same directory and run my script
> through them?
>
> Regards,
>
> David
>
> Daniel Folkinshteyn <dfolkins_at_gmail.com> ha escrito:
>
> well, where are you getting the filename in the first place? are you
>> looping over a list of filenames that comes from somewhere?
>>
>> generally, for concatenating strings, look at function 'paste':
>> write.table(myoutput, paste(myfilename,"_out.txt", sep=''),sep="\t")
>>
>> on 06/06/2008 11:51 AM DAVID ARTETA GARCIA said the following:
>>
>>> Hi list,
>>>
>>> Is it possible to save the name of a filename automatically when reading
>>> it using read.table() or some other function?
>>> My aim is to create then an output table with the name of the original
>>> table with a suffix like _out
>>>
>>> example:
>>>
>>> mydata = read.table("Run224_v2_060308.txt", sep = "\t", header = TRUE)
>>>
>>> ## store name?
>>>
>>> myfile = the_name_of_the_file
>>>
>>> ## do analysis of data and store in a data.frame "myoutput"
>>> ## write output in tab format
>>>
>>> write.table(myoutput, c(myfile,"_out.txt"),sep="\t")
>>>
>>> the name of the new file will be
>>>
>>> "Run224_v2_060308_out.txt"
>>>
>>> Thanks in advanve,
>>>
>>>
>>>
>>> David
>>>
>>> ______________________________________________
>>> R-help_at_r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org 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.
Received on Mon 09 Jun 2008 - 14:26:33 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 09 Jun 2008 - 15:30:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive