Created
September 30, 2022 17:59
-
-
Save jmbarbone/0f7f9994e9db4be8970e8d3ec98fe5ff to your computer and use it in GitHub Desktop.
Dealing with \n in text
This file contains hidden or 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
text <- { | |
" | |
Line 1 \n info | |
Line 2 \n info | |
Line 3 | |
Line 4 | |
" | |
} | |
print(text) | |
#> [1] "\n Line 1 \n info\n Line 2 \n info\n Line 3\n Line 4\n " | |
writeLines(text) | |
#> | |
#> Line 1 | |
#> info | |
#> Line 2 | |
#> info | |
#> Line 3 | |
#> Line 4 | |
#> | |
lines <- gsub("\\b\\s\n\\s\\b", " \\\\n ", text) | |
print(lines) | |
#> [1] "\n Line 1 \\n info\n Line 2 \\n info\n Line 3\n Line 4\n " | |
writeLines(lines) | |
#> | |
#> Line 1 \n info | |
#> Line 2 \n info | |
#> Line 3 | |
#> Line 4 | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment