[R] tidy.source() gets confused when # is not a comment but a part of a literal string?

Yihui Xie xie at yihui.name
Sun Feb 17 03:49:51 CET 2013


Please scroll down to Section 7: https://github.com/yihui/formatR/wiki

And this has been reported at
https://github.com/yihui/formatR/issues/26 I'll try to fix it after R
3.0 is released.

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Sat, Feb 16, 2013 at 8:19 PM, Andre Zege <azege at yahoo.com> wrote:
> I needed to clean someone else code and run it through tidy.source. It encountered a number of hangups which after some experimentation lead me to suspect that the culprit is # symbol when it is a part of literal string. For example if i copy the following to the clipboard
>
> confuse.tidy <-
>   function()
> {
>   txt <- 'abra # cadabra'
> }
>
> and run with default arguments
>
>>tidy.source()
>
> I am getting
> Error in base::parse(text = text, srcfile = NULL) :
>   4:46: unexpected INCOMPLETE_STRING
> 4: txt <- 'abra  %InLiNe_IdEnTiFiEr% "# cadabra'"
> 5: }
>
> However, good news, as i realized after a bit of struggle, is that i could do
>
>>tidy.source(keep.comment=F)
>
> which produces desired
>
> confuse.tidy <- function() {
>     txt <- "abra # cadabra"
> }
>
>
> Unfortunately, # is sometimes a legitimate part of strings, for example when you grep through lines from a web page, or when you specify a color in a string with #. So, I thought it'd be useful to point this out so that someone think of a workaround for this as dropping comments  sometimes means dropping something valuable.
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list