Installing R Packages Error in readRDS(file) : error reading from connection

后端 未结 9 1534
鱼传尺愫
鱼传尺愫 2021-01-03 19:48

Whenever I try to install any package in R on Ubuntu 14.04, I\'m getting the following error:

Error in readRDS(file) : error reading from connection
<         


        
9条回答
  •  悲&欢浪女
    2021-01-03 20:22

    If you have one or more incorrectly installed packages (e.g. because you had to force-reboot during installation) you need to re-install this/these package(s). You can find them using this code:

    library(purrr)
    
    .libPaths() %>%
    set_names() %>%
    map(function(lib) {
        .packages(all.available = TRUE, lib.loc = lib) %>%
        keep(function(pkg) {
            f <- system.file('Meta', 'package.rds', package = pkg, lib.loc = lib)
            tryCatch({readRDS(f); FALSE}, error = function(e) TRUE)
        })
    })
    

    This will return a nested list containing the broken packages:

    $`/home/yourname/R`
    [1] "brokenpkg"
    
    $`/usr/lib64/R/library`
    character(0)
    
    $`/usr/share/R/library`
    character(0)
    

    You might need to delete the directories 00LOCK- that R created in the library location while trying to install the packages.

提交回复
热议问题