问题描述
我在某个时候安装了软件包packrat
,也许只使用了一次,然后继续生活.
I installed the package packrat
at some point, used it perhaps once and moved on with my life.
但是,尽管几个月没有加载它,但仍然对我的常规R使用情况造成了麻烦.
However, despite not having loaded it in months, it remains a nuisance to my regular R usage.
看似随机,我在RStudio中的R会话会因某些操作(尤其是软件包安装)的错误而失败.这是最新的错误消息(运行parallel::makeCluster(parallel::detectCores())
之后:
Seemingly at random, my R session within RStudio will fail with errors at certain operations, especially package installation. Here's the most recent error message (after running parallel::makeCluster(parallel::detectCores())
:
通话:来源->文件
此外:警告消息:
在 file(filename, "r", encoding = encoding)
:无法打开文件 'packrat/init.R':没有这样的文件或目录
In file(filename, "r", encoding = encoding)
: cannot open file 'packrat/init.R': No such file or directory
执行停止
我检查了.libPaths()
上的所有文件夹,甚至都没有安装packrat
.为什么地球上R
仍在尝试执行packrat
操作?而我该如何阻止呢?
I checked all of the folders on .libPaths()
and I don't even have packrat
installed anymore. Why on earth is R
still trying to carry out packrat
operations? And how can I stop this?
到目前为止,我的风管胶带解决方案是简单地关闭并重新打开RStudio,这对于解决软件包安装问题非常有用.
My duct-tape solution so far is to simply close and reopen RStudio, which works like a charm for package installation issues.
但是,我似乎无法在一个 .R
脚本中解决makeCluster(detectCores())
这个问题.在另一个项目的另一个脚本中,它工作得很好.
However, I cannot seem to get around this for makeCluster(detectCores())
within just one .R
script I've got. It works perfectly fine in another script for another project.
背景:
sessionInfo()
# R version 3.2.2 (2015-08-14)
# Platform: x86_64-pc-linux-gnu (64-bit)
# Running under: Ubuntu 14.04.2 LTS
# locale:
# [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
# [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
# [7] LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8 LC_ADDRESS=en_US.UTF-8
# [10] LC_TELEPHONE=en_US.UTF-8 LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=en_US.UTF-8
# attached base packages:
# [1] parallel stats graphics grDevices utils datasets methods base
# other attached packages:
# [1] doParallel_1.0.8 iterators_1.0.7 foreach_1.4.2 geosphere_1.4-3 xlsx_0.5.7 xlsxjars_0.6.1
# [7] rJava_0.9-6 xtable_1.7-4 sandwich_2.3-3 texreg_1.35 maptools_0.8-36 sp_1.1-1
# [13] ggmap_2.5.2 ggplot2_1.0.1 data.table_1.9.5
# loaded via a namespace (and not attached):
# [1] Rcpp_0.11.6 plyr_1.8.3 tools_3.2.2 digest_0.6.8 gtable_0.1.2
# [6] lattice_0.20-33 png_0.1-7 mapproj_1.2-4 proto_0.3-10 stringr_1.0.0
# [11] RgoogleMaps_1.2.0.7 maps_2.3-11 grid_3.2.2 jpeg_0.1-8 foreign_0.8-66
# [16] RJSONIO_1.3-0 reshape2_1.4.1 magrittr_1.5 codetools_0.2-11 scales_0.2.5
# [21] MASS_7.3-43 colorspace_1.2-6 stringi_0.5-9003 munsell_0.4.2 chron_2.3-47
# [26] rjson_0.2.15 zoo_1.7-12
更新1:
安装packrat
无效.运行packrat::init()
导致在完成之前出错.没什么改变.
Update 1:
Installing packrat
had no effect. Running packrat::init()
resulted in an error before finishing; nothing changed.
我通过确定是引起问题的工作目录来隔离问题.我正在使用的工作目录中的什么可能导致了问题?以前在此目录中运行过packrat
会产生一些残留文件吗?
I've isolated the problem by identifying that it's the working directory that's causing the issues. What in the working directory I'm using might be causing the problems? Some residual file from having run packrat
previously in this directory?
推荐答案
考虑到@BondedDust的优点,通过进一步的尝试和错误,我终于似乎解决了该问题.以前曾尝试在我正在使用的特定工作目录中使用packrat
,尽管后来卸载了packrat
,但似乎留下了一些痕迹.
Through further trial and error given the prods of @BondedDust I finally appear to have solved the issue. Having previously tried to use packrat
in the particular working directory in which I was working appears to have left some vestiges despite later uninstalling packrat
.
尤其是, packrat
会编辑您的本地.Rprofile
(原始功劳(由于@zerweck和@snaut),在该目录的R启动时source()
d.
In particular, packrat
edits your local .Rprofile
(original credit due to @zerweck and @snaut), which is source()
d on R startup in that directory.
如果使用.Rprofile
存储一些本地配置,则应编辑文件并删除packrat
行(或任何您不认识的行);否则,您应该删除该文件以使您的项目恢复到预期的状态.
If you use the .Rprofile
to store some local configurations, you should edit the file and remove the packrat
lines (or any you don't recognize); otherwise, you should just delete that file to restore your project to working as expected.
这篇关于Packrat损坏R功能时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!