Automated way to for removing double line break from code?

I have a lot of code that has double line breaks in it:

 `Correct Answer` =

    c(
      39,

      "1756",

      13,

      "156",

      "910,000",

      "4,160",

      "2,159",

      "5,941",

      "524.0",

      "18.7"
    )

Is there an automated way I could remove the double line breaks? I tried styler::tidyverse_style() but it doesn't seem like that will work.

If you're using RStudio you can use the find-and-replace feature with a regular expression to probably get most of the way there.

Alternatively, R scripts are just plain-text files so you can probably use a command-line tool to achieve this.

With the CRAN version of {styler} (1.6.2), I get:

styler::style_text('
 `Correct Answer` =

    c(
      39,

      "1756",

      13,

      "156",

      "910,000",

      "4,160",

      "2,159",

      "5,941",

      "524.0",

      "18.7"
    )')
#> 
#> `Correct Answer` <-
#>   c(
#>     39,
#>     "1756",
#>     13,
#>     "156",
#>     "910,000",
#>     "4,160",
#>     "2,159",
#>     "5,941",
#>     "524.0",
#>     "18.7"
#>   )

Created on 2021-12-05 by the reprex package (v2.0.1)

Alternatively, the Addin or the other style_*() functions give the same result, so maybe you just need to update the {styler} package.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.