Created
January 5, 2021 21:11
-
-
Save sckott/52e9b47df138d805885db5972af017df 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
# 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