prettycode icon indicating copy to clipboard operation
prettycode copied to clipboard

Fix multiline strings (common) and symbols (not common I hope)

Open gaborcsardi opened this issue 9 years ago • 5 comments

gaborcsardi avatar Nov 15 '16 13:11 gaborcsardi

I believe that might be the issue I wanted to report. In the following code snippet, only the first line is highlighted: "hourly <- input %>%\n mutate(timestamp = floor_date(timestamp, "hours")) %>%\n group_by(meter, timestamp) %>%\n summarise(usage = sum(usage))"

lbartnik avatar Nov 23 '18 08:11 lbartnik

@lbartnik

This works file for me:

f <-  function() {
  hourly <- input %>%
    mutate(timestamp = floor_date(timestamp, "hours")) %>%
    group_by(meter, timestamp) %>%
    summarise(usage = sum(usage))
}
f
screen shot 2018-11-23 at 9 21 00 am

gaborcsardi avatar Nov 23 '18 09:11 gaborcsardi

I run it on a string which is pre-formatted, so I only thought of adding syntax highlighting but not of re-formatting.

highlight

lbartnik avatar Nov 28 '18 06:11 lbartnik

It isn't clear to me what is intended here. The cat screenshot isn't a function, so it isn't clear to me how {prettycode} would impact it.

jonthegeek avatar Aug 15 '24 18:08 jonthegeek

Reprex:

f <- function() {
  print("Multiline
             strings
             are 
             ok")
}
highlight(deparse(f))
#> [1] "\033[31mfunction\033[39m \033[33m(\033[39m\033[33m)\033[39m "
#> [2] "\033[33m{\033[39m"
#> [3] "    \033[36mprint\033[39m\033[34m(\033[39m\033[33m\"Multiline\\n             strings\\n             are \\n             ok\"\033[39m\033[34m)\033[39m"
#> [4] "\033[33m}\033[39m"

The multi-line string is collapsed into a single line.

gaborcsardi avatar Aug 18 '24 07:08 gaborcsardi