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

Errors while running climate matching #93

Closed
SanderDevisscher opened this issue Jul 22, 2022 · 3 comments · Fixed by #94
Closed

Errors while running climate matching #93

SanderDevisscher opened this issue Jul 22, 2022 · 3 comments · Fixed by #94
Assignees
Labels

Comments

@SanderDevisscher
Copy link
Contributor

This line of code is the probable cause of the error below:

if(length(taxon_key) == 1 & is.na(taxon_key)){

Error in if (length(taxon_key) == 1 & is.na(taxon_key)) { :
the condition has length > 1

this is an other error I get:

Error:
! Can't subset .data outside of a data mask context.

the error only occurs when maps == TRUE
this is the rlang::last_error() printout:

Backtrace:

  1. trias::climate_match(...)
  2. leaflet::addCircleMarkers(...)
  3. leaflet::invokeMethod(...)
  4. leaflet::evalFormula(list(...), data)
  5. leaflet evalAll(list)
  6. base::lapply(x, evalAll)
  7. leaflet FUN(X[[i]], ...)
  8. leaflet:::resolveFormula(x, data)
  9. [ base::eval(...) ] with 1 more call
    Run rlang::last_trace() to see the full context.

and the last_trace:

  1. ├─trias::climate_match(...)
  2. │ └─... %>% ... at trias/R/climate_match.R:491:4
  3. ├─leaflet::addPolygons(., data = sea, fillColor = "#e0e0e0", weight = 0.5)
  4. │ ├─... %>% expandLimitsBbox(pgons)
  5. │ └─leaflet::invokeMethod(...)
  6. │ └─leaflet::dispatch(...)
  7. ├─leaflet::expandLimitsBbox(., pgons)
  8. │ └─leaflet::expandLimits(map, bbox[2, ], bbox[1, ])
  9. ├─leaflet::addLayersControl(., baseGroups = ~.data$acceptedScientificName)
  10. │ ├─leaflet::invokeMethod(...)
  11. │ │ └─crosstalk::is.SharedData(data)
  12. │ └─leaflet::getMapData(map)
  13. ├─leaflet::addLegend(...)
  14. │ ├─leaflet::invokeMethod(map, data, "addLegend", legend)
  15. │ │ └─crosstalk::is.SharedData(data)
  16. │ └─leaflet::getMapData(map)
  17. ├─leaflet::addLegend(...)
  18. │ ├─leaflet::invokeMethod(map, data, "addLegend", legend)
  19. │ │ └─crosstalk::is.SharedData(data)
  20. │ └─leaflet::getMapData(map)
  21. ├─leaflet::addCircleMarkers(...)
  22. │ ├─... %>% expandLimits(pts$lat, pts$lng)
  23. │ └─leaflet::invokeMethod(...)
  24. │ └─leaflet::evalFormula(list(...), data)
  25. │ └─leaflet evalAll(list)
  26. │ └─base::lapply(x, evalAll)
  27. │ └─leaflet FUN(X[[i]], ...)
  28. │ └─leaflet:::resolveFormula(x, data)
  29. │ └─base::eval(f[[2]], metaData(data), environment(f))
  30. │ └─base::eval(f[[2]], metaData(data), environment(f))
  31. │ ├─acceptedScientificName
  32. │ └─rlang:::$.rlang_fake_data_pronoun(.data, acceptedScientificName) #=> suspected cause of error
  33. │ └─rlang:::stop_fake_data_subset(call)
  34. │ └─rlang::abort(...)
  35. └─leaflet::expandLimits(., pts$lat, pts$lng)
@SanderDevisscher SanderDevisscher self-assigned this Jul 22, 2022
SanderDevisscher added a commit that referenced this issue Jul 22, 2022
SanderDevisscher added a commit that referenced this issue Jul 22, 2022
SanderDevisscher added a commit that referenced this issue Jul 26, 2022
@SanderDevisscher
Copy link
Contributor Author

sf does not work while intersecting with the observed$"1980-2016" shape due to validity issues.

Originally I used this more up to date 1980 - 2016 shape from Beck et al. 2018 to intersect with observations after 2000.
But since it does not work as wished I'm forced to switch to using 2001 - 2025 shape from Rubel & Kottek 2010

below the code I used in an effort to fix the 1980-2016 shape

else{
        obs_shape <- sf::st_as_sf(observed$"1980-2016", crs = 4326)
        obs_shape <- sf::st_cast(obs_shape, to = "POLYGON")
        obs_shape <- sf::st_make_valid(obs_shape)
        obs_shape <- obs_shape %>% 
          rename(GRIDCODE = gridcode)
      }

and a print out of the error

! Assigned data value must be compatible with existing data.
✖ Existing data has 10000 rows.
✖ Assigned data has 2 rows.
ℹ Only vectors of size 1 are recycled.

SanderDevisscher added a commit that referenced this issue Jul 27, 2022
SanderDevisscher added a commit that referenced this issue Jul 27, 2022
SanderDevisscher added a commit that referenced this issue Jul 27, 2022
#93 in the hope to reduce the No data rows.
SanderDevisscher added a commit that referenced this issue Jul 27, 2022
#93

I added some logic to split the observations in more manageable subsets of 10000 records
Due to issues decribed in #93 (comment)
I was forced to remove the logic for the 1980-2016 shape from beck et al. 2018
SanderDevisscher added a commit that referenced this issue Jul 27, 2022
#93

Due to grouping based on year_cat (see L308-L312) calculation of No obs in climate zone & No obs in total should be based on n_obs instead of on the No rows.
SanderDevisscher added a commit that referenced this issue Jul 27, 2022
@SanderDevisscher
Copy link
Contributor Author

I just need to fix the errors with the maps

@SanderDevisscher
Copy link
Contributor Author

and switch those to sf use

SanderDevisscher added a commit that referenced this issue Aug 3, 2022
SanderDevisscher added a commit that referenced this issue Aug 3, 2022
SanderDevisscher added a commit that referenced this issue Aug 3, 2022
SanderDevisscher added a commit that referenced this issue Aug 3, 2022
SanderDevisscher added a commit that referenced this issue Aug 3, 2022
@SanderDevisscher SanderDevisscher linked a pull request Aug 4, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

1 participant