Skip to content

Restyle expression-derived source with styler #94

@jennybc

Description

@jennybc

Expression input generally gets processed with formatR::tidy_source() due to the addition of this line in the .R source file:

knitr::opts_chunk$set(tidy = TRUE, tidy.opts = list(indent = 2))

But this does not play well with the bang-bang syntactic sugar from tidyeval:

formatR::tidy_source(
  text = c(
    "nameshift <- c(SL = 'Sepal.Length')",
    "head(dplyr::rename(iris[,1:2], !!!nameshift), 3)"
  )
)
#> nameshift <- c(SL = "Sepal.Length")
#> head(dplyr::rename(iris[, 1:2], !(!(!nameshift))), 3)

styler is under development and its non-invasive quality works to our advantage:

styler::style_text(
  c(
    "nameshift <- c(SL = 'Sepal.Length')",
    "head(dplyr::rename(iris[,1:2], !!!nameshift), 3)"
  )
)
#> [1] "nameshift <- c(SL = \"Sepal.Length\")"            
#> [2] "head(dplyr::rename(iris[, 1:2], !!!nameshift), 3)"

Switch to that once it's on CRAN.

cc @krlmlr @lorenzwalthert

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions