Quantcast

How to open a file with a name changed?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

How to open a file with a name changed?

Minerva Mora
Hi, I apologize for my english.

I´m trying to read a file, but the name of this file changes every day, for example: today is May 24, 2012

bonos<- read.table("C:/Bonos/20120524.csv", header=TRUE, sep="\t")

So, tomorrow I want to read the file again, but i don´t want to put the date by myself, i want this automatically. I know that if a put day() this instruccion gives me the date.

My problem is, I don´t know how to concatenate these:
-"C:/Bonos/
-the date
-.csv"
 
I tried this:
bonos<- read.table(cat(cit,dia,extension), header=TRUE, sep="\t")
where
--cit is "\"C:/Bonos/"
--dia is dia<-format(today, "%Y%m%d")
--extension is extension<-".csv\""

but i have this problem:
"C:/Bonos/ 20120524 .csv"Error in read.table(cat(cit, dia, extension), header = TRUE, sep = "\t") :   'file' must be a character string or connection

What can i do?

Thanks!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to open a file with a name changed?

Rolf Turner-3

?paste

On 25/05/12 11:45, Minerva Mora wrote:

> Hi, I apologize for my english.
>
> I´m trying to read a file, but the name of this file changes every day, for
> example: today is May 24, 2012
>
> bonos<- read.table("C:/Bonos/*20120524*.csv", header=TRUE, sep="\t")
>
> So, tomorrow I want to read the file again, but i don´t want to put the date
> by myself, i want this automatically. I know that if a put day() this
> instruccion gives me the date.
>
> My problem is, I don´t know how to concatenate these:
> -"C:/Bonos/
> -the date
> -.csv"
>
> I tried this:
> bonos<- read.table(cat(cit,dia,extension), header=TRUE, sep="\t")
> where
> --cit is *"\"C:/Bonos/"*
> --dia is *dia<-format(today, "%Y%m%d")*
> --extension is *extension<-".csv\""*
>
> but i have this problem:
> "C:/Bonos/ 20120524 .csv"*Error in read.table(cat(cit, dia, extension),
> header = TRUE, sep = "\t") : * * 'file' must be a character string or
> connection*
>
> What can i do?
>
> Thanks!
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-open-a-file-with-a-name-changed-tp4631261.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to open a file with a name changed?

Steve Taylor
In reply to this post by Minerva Mora
You probably want to use paste or paste0 instead of cat.
paste0(cit,dia,extension)

Also, this might work:
tail(dir("C:/Bonos/",patt="csv$"),1)


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Minerva Mora
Sent: Friday, 25 May 2012 11:45a
To: [hidden email]
Subject: [R] How to open a file with a name changed?

Hi, I apologize for my english.

I´m trying to read a file, but the name of this file changes every day, for
example: today is May 24, 2012

bonos<- read.table("C:/Bonos/*20120524*.csv", header=TRUE, sep="\t")

So, tomorrow I want to read the file again, but i don´t want to put the date
by myself, i want this automatically. I know that if a put day() this
instruccion gives me the date.

My problem is, I don´t know how to concatenate these:
-"C:/Bonos/
-the date
-.csv"
 
I tried this:
bonos<- read.table(cat(cit,dia,extension), header=TRUE, sep="\t")
where
--cit is *"\"C:/Bonos/"*
--dia is *dia<-format(today, "%Y%m%d")*
--extension is *extension<-".csv\""*

but i have this problem:
"C:/Bonos/ 20120524 .csv"*Error in read.table(cat(cit, dia, extension),
header = TRUE, sep = "\t") : * * 'file' must be a character string or
connection*

What can i do?

Thanks!

--
View this message in context: http://r.789695.n4.nabble.com/How-to-open-a-file-with-a-name-changed-tp4631261.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] 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.
______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to open a file with a name changed?

David Winsemius
In reply to this post by Minerva Mora

On May 24, 2012, at 7:45 PM, Minerva Mora wrote:

> Hi, I apologize for my english.
>
> I´m trying to read a file, but the name of this file changes every  
> day, for
> example: today is May 24, 2012
>
> bonos<- read.table(*20120524*.csv", header=TRUE, sep="\t")
>

yr = "2012"
mo = "01
dt = "25"
filnam =paste("C:/Bonos/" , yr, mo, dt,sep="")

bonos <- read.table(filnam, header=TRUE, sep="\t")


> So, tomorrow I want to read the file again, but i don´t want to put  
> the date
> by myself, i want this automatically. I know that if a put day() this
> instruccion gives me the date.
>
> My problem is, I don´t know how to concatenate these:
> -"C:/Bonos/
> -the date
> -.csv"
>
> I tried this:
> bonos<- read.table(cat(cit,dia,extension), header=TRUE, sep="\t")
> where
> --cit is *"\"C:/Bonos/"*
> --dia is *dia<-format(today, "%Y%m%d")*
> --extension is *extension<-".csv\""*
>
> but i have this problem:
> "C:/Bonos/ 20120524 .csv"*Error in read.table(cat(cit, dia,  
> extension),
> header = TRUE, sep = "\t") : * * 'file' must be a character string or
> connection*
>
> What can i do?
>
> Thanks!
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-open-a-file-with-a-name-changed-tp4631261.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to open a file with a name changed?

David Winsemius
In reply to this post by Minerva Mora

On May 24, 2012, at 7:45 PM, Minerva Mora wrote:

> Hi, I apologize for my english.
>
> I´m trying to read a file, but the name of this file changes every  
> day, for
> example: today is May 24, 2012
>
> bonos<- read.table("C:/Bonos/*20120524*.csv", header=TRUE, sep="\t")
>
> So, tomorrow I want to read the file again, but i don´t want to put  
> the date
> by myself, i want this automatically. I know that if a put day() this
> instruccion gives me the date.
>
> My problem is, I don´t know how to concatenate these:
> -"C:/Bonos/
> -the date
> -.csv"
>

or even :

paste( gsub("-", "", Sys.Date() ) )
[1] "20120524"

filname <- paste("C:/Bonos/", gsub("-", "", Sys.date() ) , sep="")

--
David.


> I tried this:
> bonos<- read.table(cat(cit,dia,extension), header=TRUE, sep="\t")
> where
> --cit is *"\"C:/Bonos/"*
> --dia is *dia<-format(today, "%Y%m%d")*
> --extension is *extension<-".csv\""*
>
> but i have this problem:
> "C:/Bonos/ 20120524 .csv"*Error in read.table(cat(cit, dia,  
> extension),
> header = TRUE, sep = "\t") : * * 'file' must be a character string or
> connection*
>
> What can i do?
>
> Thanks!
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-open-a-file-with-a-name-changed-tp4631261.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to open a file with a name changed?

Peter Dalgaard-2
In reply to this post by Rolf Turner-3

On May 25, 2012, at 02:38 , Rolf Turner wrote:

> ?paste

or ?sprintf, which might lead to more readable code. Also

> format(today, "C:/Bonos/%Y%m%d.csv")
[1] "C:/Bonos/20120525.csv"



> On 25/05/12 11:45, Minerva Mora wrote:
>> Hi, I apologize for my english.
>>
>> I´m trying to read a file, but the name of this file changes every day, for
>> example: today is May 24, 2012
>>
>> bonos<- read.table("C:/Bonos/*20120524*.csv", header=TRUE, sep="\t")
>>
>> So, tomorrow I want to read the file again, but i don´t want to put the date
>> by myself, i want this automatically. I know that if a put day() this
>> instruccion gives me the date.
....

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to open a file with a name changed?

Minerva Mora
In reply to this post by Minerva Mora
Hi!!
Thanks everybody...
It works with filname <- paste("C:/Bonos/", gsub("-", "", Sys.date() ) , sep="")

Loading...