文件错误:无法打开R项目中文件的连接

文件错误:无法打开R项目中文件的连接,r,temp,rdata,R,Temp,Rdata,我最近开始使用R项目来组织我的文件和数据 我的.Rdata文件和脚本都保存在同一个文件夹中(当前选择该文件夹作为我的工作目录)。在RStudio中,我可以看到全局环境中的所有对象,并且可以在该窗口中与它们交互,但当我尝试运行使用其中一个对象的代码行时,我会出现以下错误: > head(current.clim) 我不明白为什么它会引用一个临时文件(或者为什么这些文件保存在这里)。R项目背后的想法不是将所有这些信息放在一个地方吗 任何帮助都将不胜感激 编辑: 发布str(current.c

我最近开始使用R项目来组织我的文件和数据

我的.Rdata文件和脚本都保存在同一个文件夹中(当前选择该文件夹作为我的工作目录)。在RStudio中,我可以看到全局环境中的所有对象,并且可以在该窗口中与它们交互,但当我尝试运行使用其中一个对象的代码行时,我会出现以下错误:

> head(current.clim)
我不明白为什么它会引用一个临时文件(或者为什么这些文件保存在这里)。R项目背后的想法不是将所有这些信息放在一个地方吗

任何帮助都将不胜感激

编辑:


发布
str(current.clim)
@42的输出-在原始Post中添加了输出,我认为它回答了问题。您可以在输出中看到对临时文件的引用。当开发人员创建S4对象(从技术上讲,对象的类具有S4方法)时,他们可能会引用外部数据源以控制对象的大小。通常不鼓励使用.Rdata文件。最佳实践是使用脚本加载必要的包并从头开始构建。他们不会对你忘记在工作区中“到处乱放”的东西感到困惑,或者像在本例中一样,对你之前所做的那些你并不真正理解的事情感到困惑。我希望这是一个简单的解决方案,以避免不得不一直重新运行基本代码。我的大多数数据都相当大,需要很多小时(有时超过一天)才能执行。
Error in file(fn, "rb") : cannot open the connection
In addition: Warning message:
In file(fn, "rb") :
  cannot open file 'C:\Users\username\AppData\Local\Temp\RtmpkVd7Cc\raster\r_tmp_2020-02-06_100056_20448_29146.gri': No such file or directory
> str(current.clim)

Formal class 'RasterStack' [package "raster"] with 11 slots
  ..@ filename: chr ""
  ..@ layers  :List of 2
  .. ..$ :Formal class 'RasterLayer' [package "raster"] with 12 slots
  .. .. .. ..@ file    :Formal class '.RasterFile' [package "raster"] with 13 slots
  .. .. .. .. .. ..@ name        : chr "C:\\Users\\username\\AppData\\Local\\Temp\\RtmpkVd7Cc\\raster\\r_tmp_2020-02-06_100056_20448_29146.grd"
  .. .. .. .. .. ..@ datanotation: chr "INT2S"
  .. .. .. .. .. ..@ byteorder   : Named chr "little"
  .. .. .. .. .. .. ..- attr(*, "names")= chr "value"
  .. .. .. .. .. ..@ nodatavalue : num -32768
  .. .. .. .. .. ..@ NAchanged   : logi TRUE
  .. .. .. .. .. ..@ nbands      : int 19
  .. .. .. .. .. ..@ bandorder   : Named chr "BIL"
  .. .. .. .. .. .. ..- attr(*, "names")= chr "value"
  .. .. .. .. .. ..@ offset      : int 0
  .. .. .. .. .. ..@ toptobottom : logi TRUE
  .. .. .. .. .. ..@ blockrows   : int 0
  .. .. .. .. .. ..@ blockcols   : int 0
  .. .. .. .. .. ..@ driver      : chr "raster"
  .. .. .. .. .. ..@ open        : logi FALSE
  .. .. .. ..@ data    :Formal class '.SingleLayerData' [package "raster"] with 13 slots
  .. .. .. .. .. ..@ values    : logi(0) 
  .. .. .. .. .. ..@ offset    : num 0
  .. .. .. .. .. ..@ gain      : num 1
  .. .. .. .. .. ..@ inmemory  : logi FALSE
  .. .. .. .. .. ..@ fromdisk  : logi TRUE
  .. .. .. .. .. ..@ isfactor  : logi FALSE
  .. .. .. .. .. ..@ attributes: list()
  .. .. .. .. .. ..@ haveminmax: logi TRUE
  .. .. .. .. .. ..@ min       : num -278
  .. .. .. .. .. ..@ max       : num 319
  .. .. .. .. .. ..@ band      : int 1
  .. .. .. .. .. ..@ unit      : chr ""
  .. .. .. .. .. ..@ names     : chr "layer.1"
  .. .. .. ..@ legend  :Formal class '.RasterLegend' [package "raster"] with 5 slots
  .. .. .. .. .. ..@ type      : chr(0) 
  .. .. .. .. .. ..@ values    : logi(0) 
  .. .. .. .. .. ..@ color     : logi(0) 
  .. .. .. .. .. ..@ names     : logi(0) 
  .. .. .. .. .. ..@ colortable: logi(0) 
  .. .. .. ..@ title   : chr(0) 
  .. .. .. ..@ extent  :Formal class 'Extent' [package "raster"] with 4 slots
  .. .. .. .. .. ..@ xmin: num -180
  .. .. .. .. .. ..@ xmax: num 180
  .. .. .. .. .. ..@ ymin: num -60
  .. .. .. .. .. ..@ ymax: num 90
  .. .. .. ..@ rotated : logi FALSE
  .. .. .. ..@ rotation:Formal class '.Rotation' [package "raster"] with 2 slots
  .. .. .. .. .. ..@ geotrans: num(0) 
  .. .. .. .. .. ..@ transfun:function ()  
  .. .. .. ..@ ncols   : int 8640
  .. .. .. ..@ nrows   : int 3600
  .. .. .. ..@ crs     :Formal class 'CRS' [package "sp"] with 1 slot
  .. .. .. .. .. ..@ projargs: chr "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"
  .. .. .. ..@ history : list()
  .. .. .. ..@ z       : list()
  .. ..$ :Formal class 'RasterLayer' [package "raster"] with 12 slots
  .. .. .. ..@ file    :Formal class '.RasterFile' [package "raster"] with 13 slots
  .. .. .. .. .. ..@ name        : chr "C:\\Users\\username\\AppData\\Local\\Temp\\RtmpkVd7Cc\\raster\\r_tmp_2020-02-06_100056_20448_29146.grd"
  .. .. .. .. .. ..@ datanotation: chr "INT2S"
  .. .. .. .. .. ..@ byteorder   : Named chr "little"
  .. .. .. .. .. .. ..- attr(*, "names")= chr "value"
  .. .. .. .. .. ..@ nodatavalue : num -32768
  .. .. .. .. .. ..@ NAchanged   : logi TRUE
  .. .. .. .. .. ..@ nbands      : int 19
  .. .. .. .. .. ..@ bandorder   : Named chr "BIL"
  .. .. .. .. .. .. ..- attr(*, "names")= chr "value"
  .. .. .. .. .. ..@ offset      : int 0
  .. .. .. .. .. ..@ toptobottom : logi TRUE
  .. .. .. .. .. ..@ blockrows   : int 0
  .. .. .. .. .. ..@ blockcols   : int 0
  .. .. .. .. .. ..@ driver      : chr "raster"
  .. .. .. .. .. ..@ open        : logi FALSE
  .. .. .. ..@ data    :Formal class '.SingleLayerData' [package "raster"] with 13 slots
  .. .. .. .. .. ..@ values    : logi(0) 
  .. .. .. .. .. ..@ offset    : num 0
  .. .. .. .. .. ..@ gain      : num 1
  .. .. .. .. .. ..@ inmemory  : logi FALSE
  .. .. .. .. .. ..@ fromdisk  : logi TRUE
  .. .. .. .. .. ..@ isfactor  : logi FALSE
  .. .. .. .. .. ..@ attributes: list()
  .. .. .. .. .. ..@ haveminmax: logi TRUE
  .. .. .. .. .. ..@ min       : num 0
  .. .. .. .. .. ..@ max       : num 10577
  .. .. .. .. .. ..@ band      : int 12
  .. .. .. .. .. ..@ unit      : chr ""
  .. .. .. .. .. ..@ names     : chr "layer.12"
  .. .. .. ..@ legend  :Formal class '.RasterLegend' [package "raster"] with 5 slots
  .. .. .. .. .. ..@ type      : chr(0) 
  .. .. .. .. .. ..@ values    : logi(0) 
  .. .. .. .. .. ..@ color     : logi(0) 
  .. .. .. .. .. ..@ names     : logi(0) 
  .. .. .. .. .. ..@ colortable: logi(0) 
  .. .. .. ..@ title   : chr(0) 
  .. .. .. ..@ extent  :Formal class 'Extent' [package "raster"] with 4 slots
  .. .. .. .. .. ..@ xmin: num -180
  .. .. .. .. .. ..@ xmax: num 180
  .. .. .. .. .. ..@ ymin: num -60
  .. .. .. .. .. ..@ ymax: num 90
  .. .. .. ..@ rotated : logi FALSE
  .. .. .. ..@ rotation:Formal class '.Rotation' [package "raster"] with 2 slots
  .. .. .. .. .. ..@ geotrans: num(0) 
  .. .. .. .. .. ..@ transfun:function ()  
  .. .. .. ..@ ncols   : int 8640
  .. .. .. ..@ nrows   : int 3600
  .. .. .. ..@ crs     :Formal class 'CRS' [package "sp"] with 1 slot
  .. .. .. .. .. ..@ projargs: chr "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"
  .. .. .. ..@ history : list()
  .. .. .. ..@ z       : list()
  ..@ title   : chr(0) 
  ..@ extent  :Formal class 'Extent' [package "raster"] with 4 slots
  .. .. ..@ xmin: num -180
  .. .. ..@ xmax: num 180
  .. .. ..@ ymin: num -60
  .. .. ..@ ymax: num 90
  ..@ rotated : logi FALSE
  ..@ rotation:Formal class '.Rotation' [package "raster"] with 2 slots
  .. .. ..@ geotrans: num(0) 
  .. .. ..@ transfun:function ()  
  ..@ ncols   : int 8640
  ..@ nrows   : int 3600
  ..@ crs     :Formal class 'CRS' [package "sp"] with 1 slot
  .. .. ..@ projargs: chr "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"
  ..@ history : list()
  ..@ z       : list()