R: package ‘utils’ in options("defaultPackages") was not found?

created at 06-04-2022 views: 24

environments

  • Linux
  • conda
  • R

problem

In the Linux environment, R4 was successfully installed using conda. But it prompts that the utils and stats packages are not found, as follows:

R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-conda-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

During startup - Warning messages:
1: package ‘utils’ in options("defaultPackages") was not found
2: package ‘stats’ in options("defaultPackages") was not found

At this time, installing the R package or running other commands will directly report errors, such as:

> install.packages("ggplot2")
Error in install.packages("ggplot2") :
  could not find function "install.packages"

solution

method1

I didn't analyze the reason, I checked it online. Find the library file ldpaths in the installation R environment, add export EDITOR=vim to the last line, it seems to be OK. as follows:

echo "export EDITOR=vim" >> /opt/conda/envs/r4py3/lib/R/etc/ldpaths

it will become normal:

R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-conda-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

However, when I packaged with docker for the second time, this error appeared again. Explain that the above method is not the fundamental solution.

method2

I checked the Internet and said that there is no which in the newly created environment of conda, just install which.

(r4py3) [root@a3ef4a44aa1f etc]# which
bash: which: command not found
(r4py3) [root@a3ef4a44aa1f etc]# yum install -y which

Indeed, after installation everything works again.

(r4py3) [root@a3ef4a44aa1f etc]# R

R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-conda-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

However, there are still some answers online saying that they installed which didn't work either.

R depends on which, which might not be present in the conda R environment. Maybe it could be as simple as to add the which-derivation to conda?

Placing ‘which’ into the conda binary folder did however not fix the issue (the R console still complains about not being able to load stats and utils packages)

Some people recommend setting set R_HOME path, others recommend reinstalling other versions of R.

I used which to solve it successfully, and there is no problem in the follow-up, so I didn't try it. There are also unsuccessful friends who can try and check more, and the big deal is to reinstall.

created at:06-04-2022
edited at: 06-05-2022: