Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terra tempdir cannot handle "~" #1195

Closed
ailich opened this issue Jun 21, 2023 · 2 comments
Closed

Terra tempdir cannot handle "~" #1195

ailich opened this issue Jun 21, 2023 · 2 comments

Comments

@ailich
Copy link
Contributor

ailich commented Jun 21, 2023

You can set a tempdir in terraOptions that contains a "~" and it is considered valid (and is valid for other functions such as writeRaster); however this will lead to an error later on when the computer attempts to write temp files there. To avoid confusion perhaps have a call to path.expand internally as this solves the issue or throw an error saying the path cannot be used.

library(terra)
#> Warning: package 'terra' was built under R version 4.3.1
#> terra 1.7.38

if(!dir.exists("~/temp")){
  dir.create("~/temp")
}

terraOptions(tempdir=("~/temp"))

r<- rast(matrix(nrow = 10000, ncol=10000))
set.seed(5)
values(r)<- rnorm(ncell(r))

terrain(r)
#> Error: [terrain] path does not exist


terraOptions(tempdir=(path.expand("~/temp")))
terrain(r)
#> |---------|---------|---------|---------|=========================================                                          
#> class       : SpatRaster 
#> dimensions  : 10000, 10000, 1  (nrow, ncol, nlyr)
#> resolution  : 1, 1  (x, y)
#> extent      : 0, 10000, 0, 10000  (xmin, xmax, ymin, ymax)
#> coord. ref. :  
#> source      : spat_4DTcZdBbRm1vP2J_24864.tif 
#> name        :        slope 
#> min value   :  0.003808846 
#> max value   : 69.063812256

Created on 2023-06-21 with reprex v2.0.2

@mdsumner
Copy link
Contributor

it's a gdal thing it doesn't normalize the tilde but will create a directory of that name

@rhijmans
Copy link
Member

Thanks; that was already done for filename arguments, but not for the tempdir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants