Skip to content

Instantly share code, notes, and snippets.

@sckott
Created January 5, 2021 21:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sckott/52e9b47df138d805885db5972af017df to your computer and use it in GitHub Desktop.
Save sckott/52e9b47df138d805885db5972af017df to your computer and use it in GitHub Desktop.
# process:
# - make a new branch: git checkout -b some-branch
# - run this script: Rscript path/to/package_strip_urls.R
# - update manual files and make sure package passes check
# - submit to cran
# - after accepted on cran - delete some-branch
have_pkg <- function(pkg) {
if (!requireNamespace(pkg, quietly = TRUE)) stop("need package ", pkg)
}
have_pkg("fs")
have_pkg("desc")
# check if its a package or not
is_pkg <- tryCatch(desc::desc(), error = function(e) e)
if (inherits(is_pkg, "error")) stop("current directory is not a package")
# R and man-roxygen directories
z = c(
fs::dir_ls("R"),
fs::dir_ls("man-roxygen", fail = FALSE)
)
if (length(z) > 0) {
for (j in z) {
lns <- readLines(j)
# get indices for lines that start with #'
lns_man_nums <- grep("#'", lns)
if (length(lns_man_nums) == 0) next
# only strip urls for lines that start with #'
for (i in lns_man_nums) {
lns[i] <- gsub("<https?\\S+\\s*>", "", lns[i])
lns[i] <- gsub("\\(https?\\S+\\s*\\)", "", lns[i])
lns[i] <- gsub("https?\\S+\\s*", "", lns[i])
}
# BEWARE: this writes back to the same file
writeLines(lns, file(j))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment