[R] Moving a file from one location to another

Rui Barradas ruipbarradas at sapo.pt
Wed Oct 17 17:25:24 CEST 2012


Hello,

Use paste0(ticker[i], "_Divs.csv")

Rui Barradas
Em 17-10-2012 16:02, FJ M escreveu:
> Thanks for this timely post for me. I'm missing something in cat to get file.rename to work for me. cat puts a NULL at the end of a string. Error: downloading  MSFT .....trying URL 'http://chart.yahoo.com/table.csv?s=MSFT&a=1&b=19&c=2003&d=9&e=17&f=2012&g=d&q=q&y=0&z=MSFT&x=.csv'
> Content type 'text/csv' length unknown
> opened URL
> downloaded 119 Kbdone.
> MSFT _Divs.csvNULL
> Error in file.rename("Stock_Divs.csv", file_name) : invalid 'to' argument
> Execution halted
>   Code: library(quantmod)##
> ## Merge Date OHLC with dividend on ex-dividend date
> ##
> ticker<-c("MSFT","KMI")
> Divs_Per_Year<-4for (i in 1:2)
> {
> Divs<-getDividends(ticker[i])
> Stock<-getSymbols.yahoo(ticker[i], from = start(Divs), src = "yahoo", verbose=TRUE, auto.assign=FALSE)
> Stock_Divs<-merge(Stock,Divs,fill=0.0)
> write.zoo(Stock_Divs, file = "Stock_Divs.csv", append = FALSE, quote = TRUE, sep = ",")
> file_name<- cat(ticker[i],"_Divs.csv")
> print(file_name)
> print
> file.rename("Stock_Divs.csv",file_name)
> }
> Best, FrankChicago
>   > From: michael.weylandt at gmail.com
>> Date: Wed, 17 Oct 2012 13:47:27 +0100
>> To: ruipbarradas at sapo.pt
>> CC: r-help at r-project.org; antony.akkara at ge.com
>> Subject: Re: [R] Moving a file from one location to another
>>
>> On Wed, Oct 17, 2012 at 12:53 PM, Rui Barradas <ruipbarradas at sapo.pt> wrote:
>>> Hello,
>>>
>>> On Windows this should be the old DOS command RENAME (or REN) and apparently
>>> the R function ?file.rename carries it's name.
>>>
>> I wasn't aware of the file.*() functions -- I'll of course retract my
>> statement that this has to be OS direct via system(). Thanks for that
>> Rui!
>>
>> Cheers,
>> Michael
>>
>> ______________________________________________
>> 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.
>




More information about the R-help mailing list