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

Example case No 4: input SpatExtent fails #45

Open
mabesa opened this issue Jan 6, 2023 · 4 comments
Open

Example case No 4: input SpatExtent fails #45

mabesa opened this issue Jan 6, 2023 · 4 comments

Comments

@mabesa
Copy link

mabesa commented Jan 6, 2023

Dear chirps package developers

When I try example case 4 (with SpatExtent as object argument) from https://docs.ropensci.org/chirps/reference/get_chirps.html as follows:

library(chirps)
library(terra)

# Case 4: input SpatExtent and return a raster within the extent
area <- ext(c(-66, -64, -6, -4))

dates <- c("2017-12-15", "2017-12-31")

r4 <- get_chirps(area, dates, server = "CHC")

I get the following error message:

Error in as.data.frame.default(object) :
cannot coerce class ‘structure("SpatExtent", package = "terra")’ to a data.frame

This version of example case 4 is not present in the reference from cran so I'm guessing it is no longer supported. Being able to download chirps data in an area of interest would, however, be a very useful feature!

Would you have a recommendation on how the chirps r package could be used to obtain data within an area of interest?

Many greetings

@kauedesousa
Copy link
Member

There is something wrong in the function when it tries to find the proper S3 method. I will work on that. Meanwhile you can use this solution. It forces the function to use the correct S3 method. It worked for me, let me know if it works for you as well.

library(chirps)
library(terra)

# Case 4: input SpatExtent and return a raster within the extent
area <- ext(c(-66, -64, -6, -4))

dates <- c("2017-12-15", "2017-12-31")

r4 <- chirps:::get_chirps.SpatVector(area, dates, server = "CHC")

plot(r4)
─ Session info ───────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.1 (2022-06-23)
 os       macOS Ventura 13.0
 system   x86_64, darwin17.0
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Oslo
 date     2023-01-06
 rstudio  2022.07.2+576 Spotted Wakerobin (desktop)
 pandoc   2.9.1.1 @ /usr/local/bin/pandoc

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 chirps      * 0.1.4   2022-01-13 [1] CRAN (R 4.2.0)
 terra       * 1.6-7   2022-08-07 [1] CRAN (R 4.2.0)
 
 [1] /Library/Frameworks/R.framework/Versions/4.2/Resources/library

@mabesa
Copy link
Author

mabesa commented Jan 6, 2023

Many thanks for the incredible quick solution @kauedesousa, it works like a charm (MS OS, R 4.2.2)!

@kauedesousa
Copy link
Member

I just pushed a new "developing" version of chirps 0.1.5. In this version you don't need to use the solution I gave some minutes ago. Let me know if it works for you.

@mabesa
Copy link
Author

mabesa commented Jan 6, 2023

Did install_github the new version: works perfectly!

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

2 participants