Created
December 28, 2020 20:15
-
-
Save MyKo101/2378bf163c394029a6f11c1e3e9a7797 to your computer and use it in GitHub Desktop.
uses remotes::install_version to get a historic account of the default arguments
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(rlang) | |
library(remotes) | |
print.historic_defaults <- function(x,...){ | |
v_list_str <- ls(x) | |
v_list <- as.numeric_version(v_list_str) | |
v_list_ordered <- v_list_str[order(v_list)] | |
for(i in 1:length(v_list_ordered)){ | |
c_v_list <- v_list_ordered[[i]] | |
cat("Version:",c_v_list,"\n") | |
cat(arg_name,"= ") | |
print(x[[c_v_list]]) | |
cat("\n") | |
} | |
} | |
v_inst <- function(pkg,ver,...){ | |
res <- tryCatch( | |
install_version( | |
pkg, | |
ver, | |
upgrade = "never", | |
dependencies = F, | |
quiet = T, | |
force = T, | |
... | |
), | |
error = function(e) "NULL" | |
) | |
res == pkg | |
} | |
get_historic_defaults <- function(pkg_name,fun_name,arg_name,n=Inf){ | |
prime_version <- packageVersion(pkg_name) | |
do_next <- TRUE | |
res <- structure(env(),class="historic_defaults") | |
count <- 0 | |
while(count < n && do_next){ | |
c_version <- packageVersion(pkg_name) | |
c_version_str <- as.character(c_version) | |
res[[c_version_str]] <- formals(fun_name,envir=asNamespace(pkg_name))[[arg_name]] | |
next_version <- paste0("< ",c_version_str) | |
do_next <- v_inst(pkg_name,next_version) | |
count <- count + 1 | |
} | |
v_inst(pkg_name,prime_version) | |
res | |
} | |
out <- get_historic_defaults("ggplot2","geom_point","data",5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment