Reputation: 11
I'm trying to do a Species distribution model and every time I close Rstudio I receive this error when trying to plot my data and can't continue from where I stopped:
> Error in file(fn, "rb") : cannot open the connection In addition: > Warning message: In file(fn, "rb") : cannot open file > '/tmp/RtmpqebvDu/raster/r_tmp_2022-10-19_154556_18241_29080.gri': No > such file or directory
Also, even if a load the previously saved environment and script, it doesn't allow me to plot any bioclim variables. I even change my OP from Ubuntu 22.04 to Ubuntu 20.04 that is more stable and the error remains the same. Idk if they are saving the rasters in a temp file but I can't load all the script over and over again every time I close RStudio.
Below is my script.
#---------packages
library(sdm)
library(dplyr)
library(tidyr)
#-------import data
setwd('/home/laislacosta/srf/B_marajoensis')
marajoensis2 <- read.csv('/home/laislacosta/srf/B_marajoensis/occumrj.csv')
#------- selection sp
mrj2 <- marajoensis2 %>%
filter(Species %in% c("Bothrops marajoensis"))
#------- select long lat
mrj2 <- mrj2 %>%
select(Longitude, Latitude)
#------- remove NA values
mrj2 <- mrj2 %>%
drop_na()
#-------- remove duplicate
mrj2 <- unique(mrj2)
#-------- bioclim variable
bio_raw <- raster::getData("worldclim", var = "bio", res = 2.5)
bio_raw <- raster::stack(list.files(path = "/home/laislacosta/srf/B_marajoensis/wc5",
pattern = "bil$",
full.names = TRUE, recursive = TRUE))
#-------- prepare data for modelling
#passo 1: create column presence mrj2$spc_marajoensis <-1
#passo 2: transform object to SpatialPointsDataFrame
coordinates(mrj2) <- c("Longitude", "Latitude")
proj4string(mrj2) <- raster::projection(raster::raster())
#passo 3: area cut
brasil <- raster::shapefile('/home/laislacosta/srf/B_marajoensis/shape/lm_bioma_250.shp')
bio <- raster::mask(bio_raw, brasil)
bio <- raster::crop(bio, brasil)
plot(bio[[1]])
save.image("all_data.RData")
Upvotes: 1
Views: 343