Skip to content

Instantly share code, notes, and snippets.

@TimTaylor
Last active August 9, 2023 11:32
Show Gist options
  • Save TimTaylor/14a1867e6ca17c5ea833f377f4157446 to your computer and use it in GitHub Desktop.
Save TimTaylor/14a1867e6ca17c5ea833f377f4157446 to your computer and use it in GitHub Desktop.
dput_raw ish type thing
funz <- function(x) {
if (!is.character(x) || length(x) != 1L || is.na(x))
stop("`x` must be a scalar character that's not NA.")
middle <- character()
go <- TRUE
i <- 1L
while(go) {
exploded <- c(")", middle, "\"")
delim <- paste(exploded, collapse = "")
if (grepl(delim, x, fixed = TRUE)) {
middle <- rep.int("-", i)
i <- i + 1L
next
}
go <- FALSE
}
start <- exploded
start[1] <- "r\""
start[length(start)] <- "("
start <- paste(start, collapse = "")
cat(start, x, delim, "\n", sep = "")
invisible(x)
}
@TimTaylor
Copy link
Author

y <- "bob)\""
funz(y)
#> r"-(bob)")-"
r"-(bob)")-" == y
#> [1] TRUE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment