Hi,
You can use list.files() of Sys.glob to get a listing of all the files
in a certain directory, e.g. to get all ".R" files and source them:
for(f in Sys.glob("C:/Documents and Settings/lma/*.R")) source(f)
cheers,
Paul
Tammy Ma wrote:> How do I source a bunch of files in different directories in R?
>
>
>> From: metal_licaling at live.com
>> To: r-help at r-project.org
>> Date: Wed, 30 Sep 2009 13:45:34 +0300
>> Subject: [R] Change directory to implement same programes
>>
>>
>> HI, R-Users,
>>
>> I have one problem:
>>
>> I have written the the programs which process all file in one
directory: for example:
>>
>> setwd("C:/Documents and Settings/lma/My
Documents/Vappu-saved/Log") as the start.
>> ..........
>>
>> But I have many folders like "Vappu-saved" and there are a
lot of files in each directory. What I want is using the same program what I
write for the above directory
>> to autimatically change directory address to implement the above
programs what I wrote. How do I realize it?
>>
>> Thanks a lot.
>>
>> Regards,
>> Lingyi
>>
>> _________________________________________________________________
>> Windows Live?: Keep your life in sync. Check it out!
>>
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009
>> [[alternative HTML version deleted]]
>>
>>
>
> _________________________________________________________________
> Show them the way! Add maps and directions to your party invites.
> http://www.microsoft.com/windows/windowslive/products/events.aspx
> [[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.
>
--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone: +3130 274 3113 Mon-Tue
Phone: +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul