Reputation: 1
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:
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
Cannot create a RasterLayer object from this file. (file does not exist)
`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
Sessioninfo:
R version 3.3.3 (2017-03-06)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X El Capitan 10.11.6
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[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
loaded via a namespace (and not attached):
[1] Rcpp_0.12.10 knitr_1.15.1 BiocGenerics_0.20.0 lattice_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
Upvotes: 0
Views: 678
Reputation: 6516
As already mentioned in the comments:
list.files("/Users/Rob/Documents/BMBT5130/Data", full.names=T, pattern="tif$")
should make your code work.
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).
Upvotes: 1