简体   繁体   English

安装路径不可写R,无法更新包

[英]installation path not writable R, unable to update packages

I am trying to install Bioconductor into R, using the code on their website.我正在尝试使用他们网站上的代码将 Bioconductor 安装到 R 中。 When I type in the code (see bellow) I get an error message saying that some packages can't be updated, the installation path is unwriteable.当我输入代码时(见下文),我收到一条错误消息,指出某些软件包无法更新,安装路径不可写。

> ## try http:// if https:// URLs are not supported
> source("https://bioconductor.org/biocLite.R")
Bioconductor version 3.4 (BiocInstaller 1.24.0), ?biocLite for help
> biocLite()
BioC_mirror: https://bioconductor.org
Using Bioconductor 3.4 (BiocInstaller 1.24.0), R 3.3.2 (2016-10-31).
installation path not writeable, unable to update packages: Matrix, mgcv,

survival生存

I can install these package by going to packages/install packages.我可以通过转到包/安装包来安装这些包。

> utils:::menuInstallPkgs()
trying URL    'https://www.stats.bris.ac.uk/R/bin/windows/contrib/3.3/Matrix_1.2-8.zip'
Content type 'application/zip' length 2775038 bytes (2.6 MB)
downloaded 2.6 MB

trying URL 'https://www.stats.bris.ac.uk/R/bin/windows/contrib/3.3/mgcv_1.8-  16.zip'
Content type 'application/zip' length 2346257 bytes (2.2 MB)
downloaded 2.2 MB

trying URL     'https://www.stats.bris.ac.uk/R/bin/windows/contrib/3.3/survival_2.40-1.zip'
Content type 'application/zip' length 5109948 bytes (4.9 MB)
downloaded 4.9 MB

package ‘Matrix’ successfully unpacked and MD5 sums checked
package ‘mgcv’ successfully unpacked and MD5 sums checked
package ‘survival’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\stxeb8\AppData\Local\Temp\Rtmp2tQZ4v\downloaded_packages

I can then go to packages/ load packages and load them succesfully and search and see that the packages are there.然后我可以去包/加载包并成功加载它们并搜索并查看包在那里。

> local({pkg <- select.list(sort(.packages(all.available =   TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
Loading required package: nlme
This is mgcv 1.8-16. For overview type 'help("mgcv-package")'.
> local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
> local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
> local({pkg <- select.list(sort(.packages(all.available =     TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
> search()
[1] ".GlobalEnv"            "package:survival"      "package:mgcv"         
[4] "package:nlme"          "package:Matrix"        "package:BiocInstaller"
[7] "package:stats"         "package:graphics"      "package:grDevices"    
[10] "package:utils"         "package:datasets"      "package:methods"      
[13] "Autoloads"             "package:base"         

But then when I go to install bioconductor it gives me the same error message that Matrix, mgcv and survival aren't able to be updated.但是当我去安装 bioconductor 时,它给了我同样的错误信息,即 Matrix、mgcv 和生存无法更新。

> ## try http:// if https:// URLs are not supported
> source("https://bioconductor.org/biocLite.R")
Bioconductor version 3.4 (BiocInstaller 1.24.0), ?biocLite for help
> biocLite()
BioC_mirror: https://bioconductor.org
Using Bioconductor 3.4 (BiocInstaller 1.24.0), R 3.3.2 (2016-10-31).
installation path not writeable, unable to update packages: Matrix, mgcv,
  survival

What can I do to be able to update these packages so I can install bioconductor?我该怎么做才能更新这些软件包以便安装 bioconductor?

In general, I would advise against changing the permission in system folders, because R should work without additional administrative rights.一般来说,我建议不要更改系统文件夹中的权限,因为 R 应该在没有额外管理权限的情况下工作。

Thus I would likewise advise against installing packages using administrative rights, as you would be required to do so in the future every time you have to update these packages!因此,我同样建议不要使用管理权限安装软件包,因为您以后每次必须更新这些软件包时都需要这样做!

To backtrace this issue and prevent to minimize it in future updates, you should perform the following steps:要回溯此问题并防止在以后的更新中将其最小化,您应该执行以下步骤:

  1. Note which packages that fail to update (already shown in the error message).请注意哪些软件包无法更新(已在错误消息中显示)。
  2. Locate the folders where all R packages are installed using .libPaths() .使用.libPaths()找到安装所有 R 包的文件夹。 This should provide two results, a destination in your home folder and a system folder .这应该提供两个结果,一个目标在您的主文件夹和一个系统文件夹

"/home/USER/R/x86_64-pc-linux-gnu-library/XX" "/usr/lib/R/library" “/home/USER/R/x86_64-pc-linux-gnu-library/XX” “/usr/lib/R/library”

  1. Install the packages with install.packages(c("PKG1", "PKG2", "PKG3")) or BiocManager::install(c("PKG1", "PKG2", "PKG3")) *使用install.packages(c("PKG1", "PKG2", "PKG3"))BiocManager::install(c("PKG1", "PKG2", "PKG3")) *
  2. Only If you have administrator rights : Manually remove the older package folders from the system folder ("/usr/lib/R/library"), using administrator rights (sudo) OR enter R with administrator rights One last time and run remove.packages(c("PKG1", "PKG2", "PKG3"), lib = "/usr/lib/R/library") .仅当您具有管理员权限时:使用管理员权限 (sudo) 手动从系统文件夹(“/usr/lib/R/library”)中删除较旧的包文件夹,或者以管理员权限输入 R最后一次并运行remove.packages(c("PKG1", "PKG2", "PKG3"), lib = "/usr/lib/R/library")

*If there are issues with the installation path, add the argument , lib = "/home/USER/R/x86_64-pc-linux-gnu-library/XX" to either of the install functions in step 3. This argument explicitly states to install in your home folder. *如果安装路径有问题,请将参数, lib = "/home/USER/R/x86_64-pc-linux-gnu-library/XX"添加到步骤 3 中的任一安装函数中。此参数明确说明安装在您的主文件夹中。

There is a single issue with this approach, at least with the official R repository on Arch Linux: Whenever R is updated, the updated version still includes packages in the system folder, that can't be updated without administrative rights.这种方法有一个问题,至少在 Arch Linux 上的官方 R 存储库中:每当 R 更新时,更新的版本仍然包含系统文件夹中的包,没有管理权限就无法更新。 Therefore for each R update, this procedure must be repeated.因此,对于每个 R 更新,必须重复此过程。 I'm especially looking at you survival !!!我特别看你survival !!!

*Edit: It is important to note that biocLite is no longer the recommended tool for installing BioConductor packages. *编辑:重要的是要注意biocLite不再是安装 BioConductor 软件包的推荐工具。 You should instead use BiocManager , which is in the official CRAN repository ( install.packages("BiocManager") ).您应该改用BiocManager ,它位于官方 CRAN 存储库( install.packages("BiocManager") )中。

**Second edit: As this answer still receives votes, I have updated and cleaned up the answer. **第二次编辑:由于这个答案仍然收到投票,我已经更新并清理了答案。

It was a permission issue for me.这对我来说是一个许可问题。 First, I identified where the packages were installed using installed.packages()[, c("Package", "LibPath")] .首先,我使用installed.packages()[, c("Package", "LibPath")]确定了软件包的安装位置。 This outputs a long 2 column matrix with the names and locations of the packages.这会输出一个包含包名称和位置的长 2 列矩阵。 Then you will see where the offending packages are.然后你会看到有问题的包在哪里。 In my case, they were at /usr/lib/R/site-library and /usr/lib/R/library .就我而言,它们位于/usr/lib/R/site-library/usr/lib/R/library Then I changed the permission of these folders by chmod (I used chmod -R 777 on the main R folder, this is my personal computer, so security is not a big concern here I think).然后我通过chmod更改了这些文件夹的权限(我在主 R 文件夹上使用了chmod -R 777 ,这是我的个人计算机,所以我认为这里的安全性不是一个大问题)。

If you are running R/Rstudio on Windows, then just open R/Rstudio as administrator.如果您在 Windows 上运行 R/Rstudio,则只需以管理员身份打开 R/Rstudio。 Right click on the icon then run as administrator右键单击该图标,然后以管理员身份运行

It looks like several 'recommended' packages are installed in two places -- maybe by an administrator account in a directory you don't have write access to, and then by RStudio in a directory where you do have write access.看起来有几个“推荐”的软件包安装在两个地方——可能是管理员帐户安装在您没有写入权限的目录中,然后是 RStudio 安装在您有写入权限的目录中。 biocLite() is complaining about the former. biocLite()抱怨前者。

Unless biocLite() complains about a Bioconductor package that cannot be installed (different from cannot be updated), there is no problem and basic Bioconductor packages have been successfully installed.除非biocLite()抱怨无法安装 Bioconductor 包(与无法更新不同),否则没有问题,基本 Bioconductor 包已成功安装。 Check out https://support.bioconductor.org for future Bioconductor-related support.查看https://support.bioconductor.org以获取未来与 Bioconductor 相关的支持。

One solution is to open a terminal and load R using admin rights一种解决方案是使用管理员权限打开终端并加载 R

sudo R
update.packages()
source("https://bioconductor.org/biocLite.R")
biocLite()

Then you can update.然后就可以更新了。 But careful.但要小心。 This can create packages by the admin in a directory supposed to be owned by a user.这可以由管理员在应该由用户拥有的目录中创建包。

In this case, instead of loading R as root (which is solving the problem until the next update), check the .libPaths().在这种情况下,不要将 R 作为 root 加载(这会在下一次更新之前解决问题),而是检查 .libPaths()。 You will have a list of directories.您将有一个目录列表。

.libPaths()
"/home/it_s_me/R/x86_64-pc-linux-gnu-library/3.4" "/usr/lib/R/library"

In my case, all packages in "/usr/lib/R/library" are owned by root, and all except one are owned by a normal user (not root) at "/home/itsame/R/x86_64-pc-linux-gnu-library/3.4".在我的情况下,“/usr/lib/R/library”中的所有软件包都归root所有,除一个以外的所有软件包都归“/home/itsame/R/x86_64-pc-linux”中的普通用户(不是root)所有-gnu 库/3.4"。

If you have admin rights, an easy solution may be to run chown in all the places: For example, I had trouble updating the curl package.如果您有管理员权限,一个简单的解决方案可能是在所有地方运行 chown:例如,我在更新 curl 包时遇到了麻烦。 I used:我用了:

sudo chown -R it_s_me /home/it_s_me/R/x86_64-pc-linux-gnu-library/3.4/curl/

I had a similar problem with other Bioconductor packages and the solution was simpler than I thought.我在使用其他 Bioconductor 软件包时遇到了类似的问题,解决方案比我想象的要简单。 I had to install some OS packages pointed out on my log: libcurl-dev , libcurl4-openssl-dev , libssl-dev .我必须安装一些在我的日志中指出的操作系统包: libcurl-devlibcurl4-openssl-devlibssl-dev

My advice is to check your R log and look for "Configuration failed because [PACKAGE] was not found. Try installing".我的建议是检查您的 R 日志并查找“配置失败,因为未找到 [PACKAGE]。尝试安装”。

Since with the version of R 3.6.1 the script http://bioconductor.org/biocLite.R returns this message " Error: With R version 3.5 or greater, install Bioconductor packages using BiocManager; see https://bioconductor.org/install " I solved the problem with the following steps:由于使用 R 3.6.1 版本,脚本http://bioconductor.org/biocLite.R返回此消息“错误:使用 R 版本 3.5 或更高版本,请使用 BiocManager 安装 Bioconductor 包;请参阅https://bioconductor.org/ install " 我通过以下步骤解决了这个问题:

  1. Get the list of directories used by R to install libraries and choose the one with write permissions using: .libPaths()获取 R 用于安装库的目录列表,并使用以下命令选择具有写入权限的目录: .libPaths()
  2. Installing the "BiocManager" library using: install.packages("BiocManager")使用安装“BiocManager”库: install.packages("BiocManager")
  3. Installation of the library "bioconductor" by forcing the directory with write permissions using: BiocManager::install("Rgraphviz", lib = "C:/Users/tizbet/Documents/R/win-library/3.6")通过使用以下命令强制具有写入权限的目录来安装库“bioconductor”: BiocManager::install("Rgraphviz", lib = "C:/Users/tizbet/Documents/R/win-library/3.6")

I worked on the following R installation:我从事以下 R 安装:

platform x86_64-w64-mingw32 , arch x86_64 , os mingw32 , system x86_64, mingw32 , version.string R version 3.6.1 (2019-07-05) platform x86_64-w64-mingw32arch x86_64os mingw32system x86_64, mingw32version.string R version 3.6.1 (2019-07-05)

I was inspired by the Kasper Thystrup Karstensen answer我受到 Kasper Thystrup Karstensen 答案的启发

尝试添加参数force = TRUE

BiocManager::install("XX", force = TRUE )

Whenever you want to work on an R-code where packages need to be installed: -每当您想处理需要安装软件包的 R 代码时:-

  • Windows: Open R-studio as 'Run as administrator' [Right click on the icon] Windows:以“以管理员身份运行”打开 R-studio [右键单击图标]
  • Linux: Run as sudo user; Linux:以 sudo 用户身份运行; else get writing rights from the administrator否则从管理员那里获得写作权限

I had same problem, and the answer is to give Root Access to R ie run R or Rstudio as administrator . 我遇到了同样的问题,答案是给Root的Root Access ,即以管理员身份运行R或Rstudio。

check this question out: installed directory not writable, cannot update packages 'boot', 'class', 'KernSmooth', 'mgcv', 'nnet', 'rpart', 'spatial' 检查这个问题: 安装目录不可写,无法更新软件包'boot','class','KernSmooth','mgcv','nnet','rpart','spatial'

Correct way to resolve this problem is as followed: 解决此问题的正确方法如下:

  1. Start R as an administrator: sudo R 以管理员身份启动R: sudo R
  2. In R console execute this: update.packages() 在R控制台中执行: update.packages()

Summary is, some latest packages are required and updating those on admin mode solve this issue. 总结是,需要一些最新的软件包,并在管理模式下更新这些软件包可以解决此问题 ` `

Ubuntu: Ubuntu:

sudo apt install libcurl-dev

Fedora:软呢帽:

sudo dnf install libcurl-devel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM