File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 1
1
library(data.table )
2
2
3
- half_slashes = function (str ) {
3
+
4
+ half_slashes = function (str , exclude = character (0 )) {
5
+ # ' Given a string, remove half of the escaping backslashes
6
+ # '
7
+ # ' @param str A string to remove backslashes from
8
+ # ' @param exclude A character vector of items to exclude from processing
9
+ # '
10
+ # ' @return A version of the input string with half of the escaping chars
11
+ # '
12
+ # ' @details An exception will be thrown if removing slashes leads to a parsing
13
+ # ' error. For example, "\\" will be converted to "\" which is not
14
+ # ' a valid string.
15
+ # '
16
+ # ' @examples
17
+ # ' half_slashes("\\\\")
18
+ # ' # [1] "\\"
4
19
deparsed = deparse(str )
5
20
6
21
half_df = data.table :: as.data.table(
@@ -13,9 +28,14 @@ half_slashes = function(str) {
13
28
half_df [, out : = paste0(half_slash , char_cap )]
14
29
half_df = unique(half_df [order(nchar(out )), ])
15
30
16
- # Removing slashes before double quoutes breaks eval
31
+ # Removing slashes before double quotes breaks eval
17
32
half_df = half_df [char_cap != ' "' ]
18
33
34
+ # Dirty fix for new lines...
35
+ for (x in exclude ) {
36
+ half_df [match == x , out : = x ]
37
+ }
38
+
19
39
halfed_deparse = mgsub(half_df $ match ,
20
40
half_df $ out ,
21
41
deparsed ,
You can’t perform that action at this time.
0 commit comments