Created
February 26, 2019 19:59
-
-
Save thomasp85/b956740c89043959c190e96991f84871 to your computer and use it in GitHub Desktop.
Single-quote styler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
transformers <- styler::tidyverse_style() | |
transformers$token$fix_quotes <- function (pd_flat) { | |
str_const <- pd_flat$token == 'STR_CONST' | |
str_const_change <- grepl('^"(.*)"$', pd_flat$text[str_const]) | |
raw_str <- sub('^"(.*)"$', '\\1', (pd_flat$text[str_const][str_const_change])) | |
raw_str <- gsub('(\\\\)?\'', '\\\\\'', raw_str) | |
raw_str <- gsub('\\\\"', '"', raw_str) | |
pd_flat$text[str_const][str_const_change] <- paste0('\'', raw_str, '\'') | |
pd_flat | |
} | |
styler::style_pkg(transformers = transformers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment