在 R 光栅循环中找不到文件 [英] File not found in R raster loop

查看:123
本文介绍了在 R 光栅循环中找不到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我尝试将 CT 图像的 tiff 文件导入 R 进行分析.我有大约 250 个 tiff 文件,我正在尝试循环分析它们.分析从裁剪开始,然后是阈值,然后根据像素强度值计算孔隙率.目前我收到此错误:

Here I am trying to import tiff files of CT images to R for analysis. I have about 250 tiff files that I am trying to analyze on a loop. The analysis starts by cropping, then thresholding, then calculating porosity based on pixel intensity values. Currently I am getting this error:

.rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", 中的错误:无法从此文件创建 RasterLayer 对象.(文件不存在)

`library(raster)
 library(rgdal)
 library(sp)`


    `project_files <- dir("/Users/Rob/Documents/BMBT5130/Data")
    for (jj in 1:length(mget(project_files)))  {
    x[jj] <- raster(paste0(project_files[jj]))
    x1 <- crop(x, extent(800,1600,700,1600))
    x[x<=35]=0
    plot(x1)
    Porosity[jj] <- (length(x1[x1<=35]))/length(x1[x1>=0])`

工作目录就是上面使用的目录

The working directory is the directory used above

会话信息:

R 版本 3.3.3 (2017-03-06)平台:x86_64-apple-darwin13.4.0(64位)运行于:OS X El Capitan 10.11.6

区域设置:[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
附带的基础包:[1] stats 图形 grDevices utils datasets 方法基础

其他附加包:[1] RBioFormats_0.0.30 rJava_0.9-8 EBImage_4.16.0 imager_0.40.2 magrittr_1.5[6] plyr_1.8.4 ROI_0.2-1 rgdal_1.2-6 raster_2.5-8 sp_1.2-4[11] tiff_0.1-5

通过命名空间加载(且未附加):[1] Rcpp_0.12.10 knitr_1.15.1 BiocGenerics_0.20.0lattice_0.20-35 jpeg_0.1-8[6] stringr_1.2.0 tools_3.3.3 parallel_3.3.3 grid_3.3.3 png_0.1-7[11] registry_0.3 abind_1.4-5 bmp_0.2 purrr_0.2.2 fftwtools_0.9-8[16] slam_0.1-40 readbitmap_0.1-4 stringi_1.1.5 locfit_1.5-9.1

任何解决此问题的帮助将不胜感激.
最好的,
罗布

Any help fixing this will be much appreciated.
Best,
Rob

推荐答案

正如评论中已经提到的:

As already mentioned in the comments:

list.files("/Users/Rob/Documents/BMBT5130/Data", full.names=T, pattern="tif$")

应该让你的代码工作.

should make your code work.

确保设置 full.names=T 以确保您获得完整的路径名,如果您正在使用 tif 文件,请考虑只搜索以tif"结尾的文件(即排除 tix.aux 文件).

Make sure to set full.names=T to ensure that you get the entire path name and if you are working woth tif files, think about only searching files that end with "tif" (i.e. exclude tix.aux files).

这篇关于在 R 光栅循环中找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆