[Rd] [WISH / PATCH] possibility to split string literals across multiple lines
Simon Urbanek
simon.urbanek at r-project.org
Wed Jun 14 15:48:22 CEST 2017
As I recall this has been discussed at least a few times (unfortunately I'm traveling so can't check the references), but the justification was never satisfactory.
Personally, I wouldn't mind string continuation supported since it makes for more readable code (I had one of my packages raise a NOTE in examples because there is no way in R to split a long hash into multiple lines), but I would be strongly against random removal of whitespaces as it's counter-intuitive, misleading and makes it impossible to continue spaces on the next line. None of the languages that I can think of with multiline strings do that as that's way too dangerous.
Cheers,
Simon
> On Jun 14, 2017, at 6:58 AM, Andreas Kersting <r-devel at akersting.de> wrote:
>
> Hi,
>
> I would really like to have a way to split long string literals across multiple lines in R.
>
> Currently, if a string literal spans multiple lines, there is no way to inhibit the introduction of newline characters:
>
> > "aaa
> + bbb"
> [1] "aaa\nbbb"
>
>
> If a line ends with a backslash, it is just ignored:
>
> > "aaa\
> + bbb"
> [1] "aaa\nbbb"
>
>
> We could use this fact to implement string splitting in a fairly backward-compatible way, since currently such trailing backslashes should hardly be used as they do not have any effect. The attached patch makes the parser ignore a newline character directly following a backslash:
>
> > "aaa\
> + bbb"
> [1] "aaabbb"
>
>
> I personally would also prefer if leading blanks (spaces and tabs) in the second line are ignored to allow for proper indentation:
>
> > "aaa \
> + bbb"
> [1] "aaa bbb"
>
> > "aaa\
> + \ bbb"
> [1] "aaa bbb"
>
> This is also implemented by this patch.
>
>
> An alternative approach could be to have something like
>
> ("aaa "
> "bbb")
>
> or
>
> ("aaa ",
> "bbb")
>
> be interpreted as "aaa bbb".
>
> I don't know the ins and outs of the parser of R (hence: please very carefully review the attached patch), but I guess this would be more work to implement!?
>
>
> What do you think? Is there anybody else who is missing this feature in the first place?
>
> Regards,
> Andreas
> <patch.diff>______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel
mailing list