jumpingrivers / namer

R package :package: for labelling chunks of RMarkdown files! :boom:
https://jumpingrivers.github.io/namer/
Other
94 stars 11 forks source link

name_dir_chunks() fails when an r chunk is commented and when finding specific characters #17

Closed gorkang closed 5 years ago

gorkang commented 5 years ago

I tried namer::name_dir_chunks("Reports/") and failed in the following bits of code:

Error 1

Full R code chunk commented inside a .Rmd <!-- ```{r plot_altmetrics_scatter, echo=FALSE, fig.height=10, fig.width=10, message=FALSE, warning=FALSE, results='asis', fig.align="center"} -->

Error in parse(text = paste("alist(", quote_label(params), ")")) :

:1:150: unexpected '->' 1: alist( '

Error 2

Here I dinamically create r code chunks (getting rid of offending characters on the fly)

knit_expanded <- paste0("\n\n### ", c, "###\n\n```{r ", gsub(' |°|Ñ', '', c), ", results='asis', fig.height=", plot_height, ", fig.width=", plot_width, ", echo=FALSE}\n\ncat("chunk")\n\n```\n\n&nbsp;&nbsp;\n\n\\newpage")

Error in parse(text = paste("alist(", quote_label(params), ")")) :

:1:69: unexpected input 1: alist( 'knit_expanded <- paste0("\n\n### ", c, "###\n\nr ", gsub(' |�
maelle commented 5 years ago

Thanks! I don't fully understand Errror 2, could you provide a full example rmd?

Regarding Error 1 out of curiosity what's the reason for commenting out chunks instead of using eval=FALSE and similar options?

gorkang commented 5 years ago

Regarding Error 2, the best simple example might be the accepted response here: https://stackoverflow.com/questions/21729415/generate-dynamic-r-markdown-blocks

Regarding Error 1. Mmmm, I guess no real reason. Something like... "hey, I'm gonna comment this as I am not using it now but I might need it in the future" :)

Cheers!

maelle commented 5 years ago

Ok so it'd be fair for us not to solve error 1, since one could use chunk options?

Will look at error 2 examples from that SO soon but an example Rmd of yours would help a lot.

gorkang commented 5 years ago

Sorry about not posting a reproducible example initially.

Here you have an Rmd file where namer::name_dir_chunks() fails (Error 2). namer_bug.zip

Regarding Error 1. Not sure how hard it will be to fix, but given commenting full chunks of code is a possibility in Rmd, the problem may come out again in the future. Maybe a regexp, "ignore everything inside " could be enough? But of course, feel free to close this :)

maelle commented 5 years ago

@gorkang can you confirm the latest version solves the errors you encountered?

gorkang commented 5 years ago

It does! Thanks!

maelle commented 5 years ago

Awesome, thanks for the bug reports, we hope the package can be useful to you! ✨