[R] When using require(), why do I get the error message "Error in if (!loaded) { : the condition has length > 1" ?

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Mon Oct 24 18:35:02 CEST 2022


Reread ?require more carefully. Especially for the  'package' argument.

Incidentally, you don't need to require base. It's always available.

-- Bert

On Mon, Oct 24, 2022 at 9:25 AM Kelly Thompson <kt1572757 using gmail.com> wrote:
>
> # Below, when using require(), why do I get the error message "Error
> in if (!loaded) { : the condition has length > 1" ?
>
> # This is my reproducible code:
>
> #create a vector with the names of the packages I want to use
> packages_i_want_to_use <- c('base', 'this_pac_does_not_exist')
>
> # Here I get error messages:
> require( packages_i_want_to_use[1] )
> #Error in if (!loaded) { : the condition has length > 1
>
> require( packages_i_want_to_use[2] )
> #Error in if (!loaded) { : the condition has length > 1
>
> # Here I get what I expect:
> require('base')
>
> require('this_pac_does_not_exist')
> #Loading required package: this_pac_does_not_exist
> #Warning message:
> #In library(package, lib.loc = lib.loc, character.only = TRUE,
> logical.return = TRUE,  :
> #  there is no package called ‘this_pac_does_not_exist’
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list