bmcandr / lis-bootcamp

A collection of information to rapidly orient new users of LIS
3 stars 0 forks source link

Add section on R usage on Discover #12

Open bmcandr opened 4 years ago

bmcandr commented 4 years ago

From Kim:

Steps for running R on Discover on SLES12 nodes:

  1. Load R module module load R/3.6.3

  2. Packages need to be downloaded to a local directory. Sample R script for downloading packages:

    #!/usr/bin/env Rscript
    
    pkg=c("rgeos", "rgdal", "sp", "raster”)
    install.packages(pkg, lib="/discover/nobackup/kslinski/rPkg2", repos='https://cloud.r-project.org', type='source')

    Note that the order that packages are installed matters – dependencies must be installed first (e.g., sp must be installed before raster). Also note that the rgdal package must be installed with the type=’source’ flag.

  3. Sample R script with package:

    #!/usr/bin/env Rscript
    
    library(ncdf4, lib.loc="/discover/nobackup/kslinski/rPkg")
    
    d='20200524'
    
    NoahMP=nc_open('LIS_RST_NOAHMP401_200909302330.d01.nc')
    Noah36=nc_open('LIS_RST_NOAH36_modis2_200910010000.d01.nc')
    old='LIS_RST_NOAHMP401_200909302330.d01.nc'
    new=paste0('LIS_RST_NOAHMP401_HACK.d01_', d, '.nc')
    print(paste0('writing new file ', new))
    file.copy(old, new, overwrite=T)

    Note that the order that packages are loaded matters – dependencies must be loaded first (e.g., sp must be loaded before raster).

bmcandr commented 4 years ago

The above information was added here: https://bmcandr.github.io/lis-bootcamp/visualizing-data.html

It could be expanded, however. Also, the installation of rgdal was unsuccessful so I need to troubleshoot that.