Created
December 30, 2022 19:56
-
-
Save gadenbuie/7fe84038a5bfd39bbcc6ef13b47a3420 to your computer and use it in GitHub Desktop.
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
snps <- | |
list(r = "~/.config/rstudio/snippets/r.snippets") %>% | |
purrr::map(readLines, warn = FALSE) %>% | |
purrr::map(paste, collapse = "\n") %>% | |
purrr::map(trimws) %>% | |
purrr::map(strsplit, split = "(^|\n)snippet ") %>% | |
purrr::map_depth(2, ~ .x[.x != ""]) %>% | |
purrr::map_depth(2, ~ { | |
nm <- gsub("^([^\n\t ]+).*", "\\1", .x) | |
names(.x) <- nm | |
.x | |
}) %>% | |
purrr::flatten() | |
# write out the snippets in the vscode json format | |
snps$r %>% | |
purrr::imap(function(body, prefix) { | |
body <- sub("^\t", "", strsplit(trimws(body), "\n")[[1]][-1]) | |
list( | |
prefix = prefix, | |
body = body | |
) | |
}) %>% | |
jsonlite::toJSON(pretty = 2, auto_unbox = TRUE) %>% | |
clipr::write_clip() | |
# Open "Configure user snippets" then "r.json" in vscode | |
# Paste the JSON into the template file | |
# Remove outer braces `{` and `}` from pasted text | |
# Remove any comments that were in the source snippets (if you have any) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment