yihui / formatR

Format R Code Automatically
https://yihui.org/formatr/
254 stars 52 forks source link

parser problem in R2.15.2 and updated packages? #27

Closed cyrus621 closed 11 years ago

cyrus621 commented 11 years ago

Last year there was the issue https://github.com/yihui/knitr/issues/18 where running knitR with highlight=TRUE resulted in the error:

Error in match(data$token, grammar_symbols$token) : 
  object 'grammar_symbols' not found

I have been using knitr w/o problems but now after updating to R2.15.2 and the latest packages I get the same problem. Code compiles with highlight=FALSE but not =TRUE

In the .Rnw source:

opts_knit$set(...., highlight=TRUE)  ## gives the above error
opts_knit$set(...., highlight=FALSE) ## no error but code does not format correctly

versions (all up-to-date via update.packages(dependencies=TRUE):

> version
               _                            
platform       x86_64-apple-darwin9.8.0     
arch           x86_64                       
os             darwin9.8.0                  
system         x86_64, darwin9.8.0          
status                                      
major          2                            
minor          15.2                         
year           2012                         
month          10                           
day            26                           
svn rev        61015                        
language       R                            
version.string R version 2.15.2 (2012-10-26)
nickname       Trick or Treat  

> 
> help(package="knitr")$info[[1]][4]
[1] "Version:            0.9"
> help(package="parser")$info[[1]][4]
[1] "Version:            0.1"
> help(package="formatR")$info[[1]][4]
[1] "Version:            0.7"
yihui commented 11 years ago

This should not be an issue of the formatR package, since it no longer depends on parser. I do not know what happened in the current version of the parser package, but I think this issue can be solved by library(parser). In future (after R 3.0.0 comes out) the dependencies on highlight and parser will be completely removed, and knitr will support native syntax highlighting.

cyrus621 commented 11 years ago

谢先生,thanks so much! Yes, that solved the problem. I suppose forcing parser to load (I used require rather than library) was necessary because formatR does not load parser any more.

Thanks so much for this wonderful package!! I was a loyal Sweave user, many thanks to Leisch for leading the way, but your solution is much more elegant. I converted with about one day of trial and error.

yihui commented 11 years ago

Glad to know the problem was solved, and thanks for the kind words :smiley: