Last active
December 27, 2021 19:26
-
-
Save bakaburg1/817be0e276d94032f1b654afb34452bb to your computer and use it in GitHub Desktop.
Scrape unbound globals which creates warnings with R CMD CHECK
This file contains 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
library(stringr) | |
library(dplyr) | |
check_logfile <- ... | |
readLines(check_logfile) %>% paste(collapse = '\n') %>% | |
str_extract_all("[\\w_]+ ?:( <anonymous>:)?[\\s\\n]+no[\\s\\n]+visible[\\s\\n]+binding[\\s\\n]+for[\\s\\n]+global[\\s\\n]+variable[\\s\\n]+‘.*’") %>% | |
lapply(function(x) { | |
fun <- str_extract(x, '^[\\w_]+') | |
var <- str_extract(x, '(?<=‘).*(?=’)') | |
data.frame(fun, var) | |
}) %>% dplyr::bind_rows() %>% | |
dplyr::group_split(fun) %>% lapply(function(x) { | |
x$var <- ifelse(make.names(x$var) == x$var, x$var, paste0("\`", x$var, "\`")) | |
vars <- paste(x$var, collapse = " <- ") %>% paste('<- NULL') | |
data.frame(fun = x$fun[1], vars) | |
}) %>% dplyr::bind_rows() %>% View |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment