How to install rgdal and/or upload raster on google-collaboration

I am trying to upload several rasters on tif format with google-collaboration. However I always had the same error message:

"Cannot create RasterLayer object from this file; perhaps you need to install rgdal first"

So, I tried to install rgdal...and another error appeared:

"Installation of package had non-zero exit status."

I tried to install using a local file, and apparently, its run ok, however, when i required the package, another error appeared:

"Error in library(rgdal) : there is no package called ‘rgdal’

/usr/local/lib/python3.6/dist-packages/rpy2/rinterface/init.py:146: RRuntimeWarning: 4: warnings.warn(x, RRuntimeWarning) /usr/local/lib/python3.6/dist-packages/rpy2/rinterface/init.py:146: RRuntimeWarning: 5: warnings.warn(x, RRuntimeWarning) /usr/local/lib/python3.6/dist-packages/rpy2/rinterface/init.py:146: RRuntimeWarning: 6: package ‘rgdal’ is not available (for R version 3.6.1)"

Could anyone help me to fix these errors?

I provide my session info and a fragment of code

R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas/liblapack.so.3

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rounding 

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  tools     stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
[1] snowfall_1.84-6.1 snow_0.4-3        biomod2_3.3-7.1   ggplot2_3.2.1    
[5] reshape_0.8.8     raster_2.9-23     sp_1.3-1         

loaded via a namespace (and not attached):
 [1] gbm_2.1.5             zoo_1.8-6             tidyselect_0.2.5     
 [4] purrr_0.3.2           splines_3.6.1         lattice_0.20-38      
 [7] colorspace_1.4-1      viridisLite_0.3.0     survival_2.44-1.1    
[10] rlang_0.4.0           hexbin_1.27.3         pillar_1.4.2         
[13] glue_1.3.1            withr_2.1.2           RColorBrewer_1.1-2   
[16] plotmo_3.5.5          plyr_1.8.4            mda_0.4-10           
[19] munsell_0.5.0         gtable_0.3.0          codetools_0.2-16     
[22] latticeExtra_0.6-28   class_7.3-15          Rcpp_1.0.2           
[25] scales_1.0.0          plotrix_3.7-6         abind_1.4-5          
[28] gridExtra_2.3         TeachingDemos_2.10    dplyr_0.8.3          
[31] dismo_1.1-4           rasterVis_0.46        grid_3.6.1           
[34] magrittr_1.5          lazyeval_0.2.2        tibble_2.1.3         
[37] PresenceAbsence_1.1.9 randomForest_4.6-14   Formula_1.2-3        
[40] crayon_1.3.4          pkgconfig_2.0.2       MASS_7.3-51.4        
[43] Matrix_1.2-17         pROC_1.15.3           assertthat_0.2.1     
[46] earth_5.1.1           R6_2.4.0              rpart_4.1-15         
[49] nnet_7.3-12           compiler_3.6.1       
%load_ext rpy2.ipython
from google.colab import drive
drive.mount('/content/drive/')
%%R
install.packages("rgdal", dependencies=TRUE,repos='http://cran.rstudio.com/') 
library(rgdal)
library(raster)
myExpl.EUR <- stack(list.files("/content/drive/My Drive/Sycios/",pattern=".tif",full.names=TRUE))    

Thank you very much in advance

Upvotes: 2

Views: 1549

Answers (1)

Robert Hijmans
Robert Hijmans

Reputation: 47201

Try this from the command line

sudo apt-get update
sudo apt-get install libgdal-dev libproj-dev 

And then in R

install.packages("rgdal")

Upvotes: 2

Related Questions