[R] Latex: Date Format conversion
Hi: Can't find a way to convert from shortDate to LongDate format. I got: 3/10/10 that I want to convert to March 10, 2010. I am using: \documentclass[11pt]{article} \usepackage{longtable,verbatim} \usepackage{ctable} \usepackage{datetime} \title{my title} \begin{document} % Convert date \dddate\3/10/10 end{document} My report is changing every two weeks so I will eventually use \Sexpr{report[1,1]} to grab the date from column 1, row 1 of a table named report but right now my report has the date formated as described above (3/10/10). Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA __ R-help@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.
Re: [R] Latex: Date Format conversion
On Jun 10, 2010, at 10:21 AM, Felipe Carrillo wrote: Hi: Can't find a way to convert from shortDate to LongDate format. I got: 3/10/10 that I want to convert to March 10, 2010. I am using: \documentclass[11pt]{article} \usepackage{longtable,verbatim} \usepackage{ctable} \usepackage{datetime} \title{my title} \begin{document} % Convert date \dddate\3/10/10 end{document} My report is changing every two weeks so I will eventually use \Sexpr{report[1,1]} to grab the date from column 1, row 1 of a table named report but right now my report has the date formated as described above (3/10/10). Felipe, Do you want the report to be dated for the day that it is processed by latex? If so, just use: \today to generate the current date at run time in the long format that you have above. HTH, Marc Schwartz __ R-help@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.
Re: [R] Latex: Date Format conversion
Marc: My report is done every two weeks and is created automatically. I click a command button on an Excel form and it runs a .rnw script in R creating a latex dynamic report. Excel sends 15 days of data to R, eg: 6/1/10 to 6/15/10. Right above my report I usually write the range of the report manually, something like Report from 6/1/10 - 6/15/10 so I want to see if latex can select that range of dates dynamically because my report dates are constantly changing. I would like latex to look at the beginning and last date of my report and fill out the dates on the fly. I can do this easily with the following: Report from \Sexpr{report[1,1]} - \Sexpr{report[1,15]} and it prints the correct values: Report from 6/1/10 - 6/15/10 But I want those values formatted like this: Report from June 01, 2010 - June 15, 2010 I am looking for a latex command to convert the dates, something like this pseudo-code: Report from \longdate\Sexpr{report[1,1]} - \longdate\Sexpr{report[1,15]} Where long date will be the format that converts 6/1/10 to June 01, 2010 Thanks for helping. - Original Message From: Marc Schwartz marc_schwa...@me.com To: Felipe Carrillo mazatlanmex...@yahoo.com Cc: r-h...@stat.math.ethz.ch Sent: Thu, June 10, 2010 8:40:16 AM Subject: Re: [R] Latex: Date Format conversion On Jun 10, 2010, at 10:21 AM, Felipe Carrillo wrote: Hi: Can't find a way to convert from shortDate to LongDate format. I got: 3/10/10 that I want to convert to March 10, 2010. I am using: \documentclass[11pt]{article} \usepackage{longtable,verbatim} \usepackage{ctable} \usepackage{datetime} \title{my title} \begin{document} % Convert date \dddate\3/10/10 end{document} My report is changing every two weeks so I will eventually use \Sexpr{report[1,1]} to grab the date from column 1, row 1 of a table named report but right now my report has the date formated as described above (3/10/10). Felipe, Do you want the report to be dated for the day that it is processed by latex? If so, just use: \today to generate the current date at run time in the long format that you have above. HTH, Marc Schwartz __ R-help@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.
Re: [R] Latex: Date Format conversion
Felipe, I would not do the processing in TeX, but do it in R and then pass the results to the \Sexpr{}'s. If I am correctly understanding the process flow, put the following R code chunk before the point where you need to output the formatted dates: results=hide START - format(as.Date(report[1, 1], %m/%d/%y), %B %d, %Y) END - format(as.Date(report[1, 15], %m/%d/%y), %B %d, %Y) @ Then have the following in the document body: Report from \Sexpr{START} - \Sexpr{END]} To take an example of your two dates below: format(as.Date(6/1/10, %m/%d/%y), %B %d, %Y) [1] June 01, 2010 format(as.Date(6/15/10, %m/%d/%y), %B %d, %Y) [1] June 15, 2010 See ?as.Date for more information. Note, that one possible complication is that if the dates in Excel are stored as dates and not as text, that is they are exported as numbers to R, pay close attention to the last example in ?as.Date. If this is the case, then you will need to modify the R code chunk above as per the examples on the help page, to correctly convert the numbers to R's date type and then format the result as you desire. HTH, Marc On Jun 10, 2010, at 11:37 AM, Felipe Carrillo wrote: Marc: My report is done every two weeks and is created automatically. I click a command button on an Excel form and it runs a .rnw script in R creating a latex dynamic report. Excel sends 15 days of data to R, eg: 6/1/10 to 6/15/10. Right above my report I usually write the range of the report manually, something like Report from 6/1/10 - 6/15/10 so I want to see if latex can select that range of dates dynamically because my report dates are constantly changing. I would like latex to look at the beginning and last date of my report and fill out the dates on the fly. I can do this easily with the following: Report from \Sexpr{report[1,1]} - \Sexpr{report[1,15]} and it prints the correct values: Report from 6/1/10 - 6/15/10 But I want those values formatted like this: Report from June 01, 2010 - June 15, 2010 I am looking for a latex command to convert the dates, something like this pseudo-code: Report from \longdate\Sexpr{report[1,1]} - \longdate\Sexpr{report[1,15]} Where long date will be the format that converts 6/1/10 to June 01, 2010 Thanks for helping. __ R-help@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.
Re: [R] Latex: Date Format conversion
Marc: Thanks for reinforcing that, I was just trying to go that route. It seems to be simpler to import the dataset and just grab the first and last date from it and then format it. Thanks again. Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA - Original Message From: Marc Schwartz marc_schwa...@me.com To: Felipe Carrillo mazatlanmex...@yahoo.com Cc: r-h...@stat.math.ethz.ch Sent: Thu, June 10, 2010 10:19:40 AM Subject: Re: [R] Latex: Date Format conversion Felipe, I would not do the processing in TeX, but do it in R and then pass the results to the \Sexpr{}'s. If I am correctly understanding the process flow, put the following R code chunk before the point where you need to output the formatted dates: results=hide START - format(as.Date(report[1, 1], %m/%d/%y), %B %d, %Y) END - format(as.Date(report[1, 15], %m/%d/%y), %B %d, %Y) @ Then have the following in the document body: Report from \Sexpr{START} - \Sexpr{END]} To take an example of your two dates below: format(as.Date(6/1/10, %m/%d/%y), %B %d, %Y) [1] June 01, 2010 format(as.Date(6/15/10, %m/%d/%y), %B %d, %Y) [1] June 15, 2010 See ?as.Date for more information. Note, that one possible complication is that if the dates in Excel are stored as dates and not as text, that is they are exported as numbers to R, pay close attention to the last example in ?as.Date. If this is the case, then you will need to modify the R code chunk above as per the examples on the help page, to correctly convert the numbers to R's date type and then format the result as you desire. HTH, Marc On Jun 10, 2010, at 11:37 AM, Felipe Carrillo wrote: Marc: My report is done every two weeks and is created automatically. I click a command button on an Excel form and it runs a .rnw script in R creating a latex dynamic report. Excel sends 15 days of data to R, eg: 6/1/10 to 6/15/10. Right above my report I usually write the range of the report manually, something like Report from 6/1/10 - 6/15/10 so I want to see if latex can select that range of dates dynamically because my report dates are constantly changing. I would like latex to look at the beginning and last date of my report and fill out the dates on the fly. I can do this easily with the following: Report from \Sexpr{report[1,1]} - \Sexpr{report[1,15]} and it prints the correct values: Report from 6/1/10 - 6/15/10 But I want those values formatted like this: Report from June 01, 2010 - June 15, 2010 I am looking for a latex command to convert the dates, something like this pseudo-code: Report from \longdate\Sexpr{report[1,1]} - \longdate\Sexpr{report[1,15]} Where long date will be the format that converts 6/1/10 to June 01, 2010 Thanks for helping. __ R-help@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.
Re: [R] Latex: Date Format conversion
On Jun 10, 2010, at 12:19 PM, Marc Schwartz wrote: Felipe, I would not do the processing in TeX, but do it in R and then pass the results to the \Sexpr{}'s. If I am correctly understanding the process flow, put the following R code chunk before the point where you need to output the formatted dates: results=hide START - format(as.Date(report[1, 1], %m/%d/%y), %B %d, %Y) END - format(as.Date(report[1, 15], %m/%d/%y), %B %d, %Y) @ Then have the following in the document body: Report from \Sexpr{START} - \Sexpr{END]} Quick correction, just noted a typo with the ']' in the second \Sexpr{}. That should be: Report from \Sexpr{START} - \Sexpr{END} Marc __ R-help@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.