File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -818,3 +818,32 @@ as_unordered_factor <- function(x) {
818
818
class(x ) <- setdiff(class(x ), " ordered" )
819
819
x
820
820
}
821
+
822
+ # TODO: Replace me if rlang/#1730 gets implemented
823
+ # Similar to `rlang::check_installed()` but returns boolean and misses
824
+ # features such as versions, comparisons and using {pak}.
825
+ prompt_install <- function (pkg , reason = NULL ) {
826
+ if (length(pkg ) < 1 || is_installed(pkg )) {
827
+ return (TRUE )
828
+ }
829
+ if (! interactive()) {
830
+ return (FALSE )
831
+ }
832
+
833
+ pkg <- pkg [! vapply(pkg , is_installed , logical (1 ))]
834
+
835
+ message <- " The {.pkg {pkg}} package{?s} {?is/are} required"
836
+ if (is.null(reason )) {
837
+ message <- paste0(message , " ." )
838
+ } else {
839
+ message <- paste0(message , " " , reason )
840
+ }
841
+ question <- " Would you like to install {cli::qty(pkg)}{?it/them}?"
842
+
843
+ cli :: cli_bullets(c(" !" = message , " i" = question ))
844
+ if (utils :: menu(c(" Yes" , " No" )) != 1 ) {
845
+ return (FALSE )
846
+ }
847
+ utils :: install.packages(pkg )
848
+ is_installed(pkg )
849
+ }
You can’t perform that action at this time.
0 commit comments