1

I'm trying to render a pdf using Rmarkdown and knitr. This process changes the following line of my script:

"`r format(Sys.time(), '%B %d, %Y')`"

to:

'`r format(Sys.time(), ''%B %d, %Y'')`'

Specifically, these double single quotes around ''%B %d, %Y'' are throwing up the message:

Error in yaml::yaml.load(enc2utf8(string), ...) : 
  Scanner error: while scanning for the next token at line 5, column 31found character that cannot start any token at line 5, column 31

Why is knitr making these adjustments automatically, and can it be fixed / turned off?

Thanks in advance for any advice.

I have checked the answers here YAML current date in rmarkdown but did not solve my problem unfortunately

Community
  • 1
  • 1
Marc in the box
  • 11,769
  • 4
  • 47
  • 97
  • Your fix does indeed work - it's just a different date format than we specified. The other questions correct answer did not work - and I realize now that the changing of quotes seems to happen when switching between html and pdf rendering – Marc in the box Jul 21 '16 at 09:41

1 Answers1

2

A solution could be

{r format(Sys.time(), "%a %b %d %X %Y %Z")} 

More information can be found here https://stat.ethz.ch/R-manual/R-devel/library/base/html/strptime.html , if you want to change the structure of timing

%a is Abbreviated weekday name in the current locale on this platform.

%b is Abbreviated month name in the current locale on this platform.

%d is Day of the month as decimal number (01–31)

%X is Time. Locale-specific on output

%Y is Year with century.

%Z is Time zone abbreviation as a character string (empty if not available)