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

Error in location_series() #55

Open
DanielAntonioVillar opened this issue Aug 4, 2024 · 11 comments
Open

Error in location_series() #55

DanielAntonioVillar opened this issue Aug 4, 2024 · 11 comments

Comments

@DanielAntonioVillar
Copy link

When I tried to run the location_series() command as follows:

location_series(
x = HolDatPlaeoClimDat,
bio_variables = c("bio01", "bio12", "bio05", "bio06","bio16", "bio17"),
dataset = "Krapp2021", time_bp = Holocene, nn_interpol = TRUE
)

and I got the following error:

HoloceneClimAllSpec <- location_series(
+   x = HolDatPlaeoClimDat,
+   bio_variables = c("bio01", "bio12", "bio05", "bio06","bio16", "bio17"),
+   dataset = "Krapp2021", time_bp = Holocene, nn_interpol = TRUE
+ )
Error in `[<-`:
! Assigned data `neighbours_values_mean[bio_variables]` must be compatible with row subscript `i`.
x 1 row must be assigned.
x Assigned data has 6 rows.
i Row updates require a list value. Do you need `list()` or `as.list()`?
Caused by error in `vectbl_recycle_rhs_rows()`:
! Can't recycle input of size 6 to size 1.
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/tibble_error_assign_incompatible_size>
Error in `[<-`:
! Assigned data `neighbours_values_mean[bio_variables]` must be compatible with row subscript `i`.
x 1 row must be assigned.
x Assigned data has 6 rows.
i Row updates require a list value. Do you need `list()` or `as.list()`?
Caused by error in `vectbl_recycle_rhs_rows()`:
! Can't recycle input of size 6 to size 1.
---
Backtrace:
     x
  1. +-pastclim::location_series(...)
  2. | \-pastclim::location_slice(...)
  3. |   \-pastclim::location_slice_from_region_series(...)
  4. |     +-base::`[<-`(`*tmp*`, i, bio_variables, value = `<dbl>`)
  5. |     \-tibble:::`[<-.tbl_df`(`*tmp*`, i, bio_variables, value = `<dbl>`)
  6. |       \-tibble:::tbl_subassign(x, i, j, value, i_arg, j_arg, substitute(value))
  7. |         \-tibble:::tbl_subassign_row(xj, i, value, i_arg, value_arg, call)
  8. |           +-base::withCallingHandlers(...)
  9. |           \-tibble:::vectbl_assign(x[[j]], i, recycled_value[[j]])
10. |             \-vctrs::vec_assign(x, i, value)
11. +-vctrs:::stop_recycle_incompatible_size(...)
12. | \-vctrs:::stop_vctrs(...)
13. |   \-rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)
14. |     \-rlang:::signal_abort(cnd, .file)
15. |       \-base::signalCondition(cnd)
16. \-tibble (local) `<fn>`(`<vctrs___>`)
17.   \-tibble:::vectbl_recycle_rhs_rows(value, length(i), i_arg, value_arg, call)

When I tried to run it with only one variable, I got a non-halt error. This is an example of my data:

structure(list(name = c("Struthio camelus", "Struthio camelus", 
"Struthio camelus", "Struthio camelus", "Struthio camelus", "Struthio camelus"
), longitude = c(24.633301, 25.549999, 29.0833, 23.0333, 25.5, 
24.633301), latitude = c(-27.616699, -28.6667, 25.799999, -28.205601, 
23, -27.616699)), row.names = c(NA, 6L), class = "data.frame")

at first I thought it was because I attached the tidyr package before I installed pastclim in my script, and that masked the extract function from terra, since I was getting a separate error associated with extract not working, but even removing tidyr I get this error. Holocene is a vector of the time stamps which fall within the Holocene.

@dramanica
Copy link
Member

Could you please provide me with a self contained reprex? Right now, I can't rerun your code, making it difficult to diagnose the problem. A good reprex is a few lines of code that i can just copy and paste, showing the error. Thanks.

@DanielAntonioVillar
Copy link
Author

Sure thing.

HolDatPlaeoClimDat <- read.table(text = "                        name   longitude  latitude 
1           'Struthio camelus'          24.633301 -27.61670       
2           'Struthio camelus'          25.549999 -28.66670      
3           'Struthio camelus'          29.083300  25.80000       
4           'Struthio camelus'          23.033300 -28.20560       
5           'Struthio camelus'          25.500000  23.00000      
6           'Struthio camelus'          24.633301 -27.61670      
7           'Struthio camelus'          29.600000  -0.13500      
8           'Struthio camelus'          33.750000  16.25000       
9           'Numida meleagris'          33.750000  16.25000       
10          'Struthio camelus'          33.750000  16.25000      
11          'Numida meleagris'          33.750000  16.25000       
12          'Struthio camelus'          33.750000  16.25000       
13          'Numida meleagris'          33.750000  16.25000      
14          'Struthio camelus'          33.750000  16.25000       
15          'Fulica americana'          33.750000  16.25000       ",
                 header = TRUE)


Holocene <- c(0,-1000, -2000, -3000, -4000, -5000, -6000, -7000, -8000, 
              -9000, -10000, -11000, -12000)

HoloceneClimAllSpec <- location_series(
  x = HolDatPlaeoClimDat,
  bio_variables = c("bio01", "bio12", "bio05", "bio06","bio16", "bio17"),
  dataset = "Krapp2021", time_bp = Holocene, nn_interpol = TRUE
)

@dramanica
Copy link
Member

dramanica commented Aug 5, 2024

I am away from the office today, and so with limited access to large files. However, I quickly tried the command above, simply substituting:
bio_variables = c("bio01", "bio12", "bio05", "bio06","bio16", "bio17")
with
bio_variables = c("bio01", "lai", "npp")
as I have those variables on my laptop, and I don't get any error.
Could you please try with those variables, making sure that

  1. you are using a fresh instance of R, with environment being loaded
  2. that you have installed the dev version of pastclim to make sure you have all the latest fixes (see the website for instructions on how to do that).
    Let me know how that goes.

@runbeiCheng
Copy link

Hi, we tried substituting the bio variables and it returned the same error. Also, I can confirm that we have downloaded the dev version using devtools following the instructions given in the readme file. The code now runs (albeit slowly) when using only a single bio variable and produces the expected result.

HoloceneClimAllSpec <- location_series(
+   x = HolDatPlaeoClimDat,
+   bio_variables = c("bio01", "lai", "npp"), #, "bio05", "bio06","bio16", "bio17"
+   dataset = "Beyer2020", time_bp = Holocene, nn_interpol = TRUE
+ )
Error in `[<-`:
! Assigned data `neighbours_values_mean[bio_variables]` must be compatible with row subscript `i`.
x 1 row must be assigned.
x Assigned data has 3 rows.
i Row updates require a list value. Do you need `list()` or `as.list()`?
Caused by error in `vectbl_recycle_rhs_rows()`:
! Can't recycle input of size 3 to size 1.
Run `rlang::last_trace()` to see where the error occurred.

@runbeiCheng
Copy link

Hi, with some further testing, I have identified the issue. The code seems to break when "nn_interpol = TRUE" and I have managed to run the code with multiple bio variable successfully with "nn_interpol = FALSE".

@dramanica
Copy link
Member

Hmm, there is something odd going on. The code runs fine on my machine. But the error that you get is tidyverse related; if you are in a clean R session, and only loaded pastclim, there should be no tidyverse packages loaded.
I suspect that you have some packages loaded by default which are masking functions/methods used by pastclim, thus leading to the error. Can you please post the output of:
utils::sessionInfo()

@DanielAntonioVillar
Copy link
Author

R version 4.4.0 (2024-04-24)

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

other attached packages:
[1] devtools_2.4.5 usethis_2.2.3  pastclim_2.1.0 terra_1.7-78   dplyr_1.1.4    raster_3.6-26 
[7] sp_2.1-4      

loaded via a namespace (and not attached):
 [1] utf8_1.2.4        generics_0.1.3    stringi_1.8.4     lattice_0.22-6    lme4_1.1-35.3    
 [6] digest_0.6.36     magrittr_2.0.3    grid_4.4.0        pkgload_1.3.4     fastmap_1.2.0    
[11] Matrix_1.7-0      sessioninfo_1.2.2 pkgbuild_1.4.4    urlchecker_1.0.1  promises_1.3.0   
[16] purrr_1.0.2       fansi_1.0.6       scales_1.3.0      codetools_0.2-20  cli_3.6.3        
[21] shiny_1.8.1.1     rlang_1.1.4       ellipsis_0.3.2    munsell_0.5.1     splines_4.4.0    
[26] remotes_2.5.0     cachem_1.1.0      parallel_4.4.0    tools_4.4.0       memoise_2.0.1    
[31] nloptr_2.0.3      minqa_1.2.7       colorspace_2.1-0  ggplot2_3.5.1     httpuv_1.6.15    
[36] boot_1.3-30       curl_5.2.1        mime_0.12         vctrs_0.6.5       R6_2.5.1         
[41] lifecycle_1.0.4   stringr_1.5.1     htmlwidgets_1.6.4 fs_1.6.4          MASS_7.3-60.2    
[46] miniUI_0.1.1.1    pkgconfig_2.0.3   pillar_1.9.0      later_1.3.2       gtable_0.3.5     
[51] profvis_0.3.8     glue_1.7.0        Rcpp_1.0.13       tibble_3.2.1      tidyselect_1.2.1 
[56] rstudioapi_0.16.0 xtable_1.8-4      htmltools_0.5.8.1 nlme_3.1-165      compiler_4.4.0   

@dramanica
Copy link
Member

You seem to have quite a few packages loaded! To narrow down the source of your crash, we need to figure out if the problem arises without any conflicting packages (it works on my machine and GitHub continuous integration, but there could be something about your setup that is different).
If you are working on RStudio, can you please go under "Session/Restart R". That will give you a clean environment without lots of packages. You can check with utils::sessionInfo(). To give you an idea, after I load pastclim in a clean environment, all I have is:

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

other attached packages:
[1] pastclim_2.1.0.9002 terra_1.7-78       

loaded via a namespace (and not attached):
[1] compiler_4.4.1    tools_4.4.1       rstudioapi_0.16.0 Rcpp_1.0.13       codetools_0.2-20 

Then, in a clean environment, try running the reprex you sent me, and let's see if the code succeeds.

@DanielAntonioVillar
Copy link
Author

Re-ran the code in a clean environment, the same issue occurs when nn_interpol = TRUE

@dramanica
Copy link
Member

Is the error the same? It should at the very least look different, if you don't have any tidyverse package loaded. Otherwise it means that there are still some packages loaded that shouldn't be there, and that are causing conflicts. Can you please post a summary of your clean environment with utils::sessionInfo()? What operating system are you using?

@dramanica
Copy link
Member

Any update on this?

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