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

Update climate_match.R #111

Merged
merged 34 commits into from
Apr 26, 2024

Conversation

soriadelva
Copy link
Collaborator

@soriadelva soriadelva commented Mar 8, 2024

fixes #110

Function converted to work on sf package instead of sp package. World maps imported via package rnaturalworld instead of rworldwap. Possible issue: this package may consider continents a little differently (e.g., Greenland is not a part of Europe while in rworldmap it was considered a part of Europe)

#110

Function converted to work on sf package instead of sp package. World maps imported via package rnaturalworld instead of rworldwap. Possible issue: this package may consider continents a little differently (e.g., Greenland is not a part of Europe while in rworldmap it was considered a part of Europe)
@soriadelva soriadelva self-assigned this Mar 8, 2024
@soriadelva soriadelva linked an issue Mar 8, 2024 that may be closed by this pull request
@soriadelva soriadelva marked this pull request as draft March 8, 2024 14:41
@damianooldoni
Copy link
Collaborator

Thanks @soriadelva!

I would do as follows:

  1. when done, transform this draft to a Pull Request (PR).
  2. @SanderDevisscher: please, review the functionality as you are the best person to do that, I think.
  3. I will do a more software related review, without really going to check the functionality.

Fix bugs, rewrite code to follow up download status
@soriadelva soriadelva marked this pull request as ready for review March 11, 2024 12:24
R/climate_match.R Outdated Show resolved Hide resolved
Copy link
Contributor

@SanderDevisscher SanderDevisscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#' require('rgdal')

rgdal & rworldmap are no longer required/used. They should be removed from documentation.

Copy link
Contributor

@SanderDevisscher SanderDevisscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also add dplyr:: to L286 case_when & L296 n()

R/climate_match.R Outdated Show resolved Hide resolved
R/climate_match.R Outdated Show resolved Hide resolved
Copy link
Contributor

@SanderDevisscher SanderDevisscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently some function outputs have nonsensical columns. For example unfiltered has a geometry column containing point geometries while this dataframe exists of 1 row per species & climate zone combination. I would drop the geometry column using sf::st_drop_geometry(). Alternatively we can mutate the column to contain the polygon geometries of the climate zone.

Also the case for cm & filtered.

@SanderDevisscher SanderDevisscher marked this pull request as draft March 12, 2024 16:08
@soriadelva soriadelva marked this pull request as ready for review March 22, 2024 15:26
Copy link
Contributor

@SanderDevisscher SanderDevisscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devtools::check() yields the following warnings & notes

checking dependencies in R code ... WARNING
  '::' or ':::' import not declared from: 'rnaturalearth'
  Namespaces in Imports field not imported from:
    'methods' 'raster' 'rworldmap' 'sp'
    All declared Imports should be used.

❯ checking package dependencies ... NOTE
  Imports includes 25 non-default packages.
  Importing from so many packages makes the package vulnerable to any of
  them becoming unavailable.  Move as many as possible to Suggests and
  use conditionally.

❯ checking top-level files ... NOTE
  Non-standard file/directory found at top level:
    '0073402-240229165702484.zip'

❯ checking R code for possible problems ... NOTE
  apply_decision_rules: no visible binding for global variable 'n'
  apply_decision_rules: no visible binding for global variable
    'em_status'
  apply_gam: no visible binding for global variable 'em_status'
  apply_gam: no visible binding for global variable 'growth'
  apply_gam: no visible binding for global variable 'method'
  apply_gam: no visible binding for global variable 'smooth'
  apply_gam: no visible binding for global variable 'var'
  apply_gam: no visible binding for global variable 'data'
  apply_gam: no visible binding for global variable 'derivative'
  apply_gam: no visible binding for global variable 'se'
  apply_gam: no visible binding for global variable 'crit'
  apply_gam: no visible binding for global variable 'lower'
  apply_gam: no visible binding for global variable 'upper'
  climate_match: no visible binding for global variable 'legends'
  climate_match: no visible binding for global variable 'observed'
  climate_match: no visible binding for global variable 'future'
  climate_match: no visible binding for global variable 'GRIDCODE2'
  climate_match: no visible binding for global variable 'n_obs'
  climate_match: no visible binding for global variable
    'acceptedTaxonKey'
  gbif_has_distribution: no visible global function definition for
    'everything'
  get_cred: no visible global function definition for 'setNames'
  get_table_pathways: no visible binding for global variable 'n'
  indicator_introduction_year: no visible binding for global variable
    'key'
  indicator_total_year: no visible binding for global variable 'key'
  indicator_total_year: no visible binding for global variable 'year'
  verify_taxa: no visible binding for global variable '.'
  Undefined global functions or variables:
    . GRIDCODE2 acceptedTaxonKey crit data derivative em_status
    everything future growth key legends lower method n n_obs observed se
    setNames smooth upper var year
  Consider adding
    importFrom("stats", "setNames", "smooth", "var")
    importFrom("utils", "data")
  to your NAMESPACE file.

PS I also did roxygen2::roxygenise()

R/climate_match.R Outdated Show resolved Hide resolved
@SanderDevisscher
Copy link
Contributor

@soriadelva I did my review of the current state if you can take a look at the devtool notes, do a devtools::check() yourself and fix any remaining (hopefully no errors,) warnings & notes and change the spatial export to a sf object I think we can merge this PR.

A suggestion for future pimping of maps would be adding the region as a polyline to all the maps and setting the default zoom to the boundingbox of the region.

@soriadelva
Copy link
Collaborator Author

@damianooldoni, when I run the devtools::check() command I receive the following warning, would you know what to do with it?:

`❯ checking data for ASCII and uncompressed saves ... WARNING

Note: significantly better compression could be obtained
      by using R CMD build --resave-data
             old_size new_size compress
future.rda      1.6Mb    852Kb    bzip2
observed.rda    1.6Mb    857Kb       xz

`

@damianooldoni
Copy link
Collaborator

Thanks @soriadelva. About the uncompressed savings issue, try to save again the .rda files using this syntax?

save(your_r_object,file="your_rda_file.rda",compress="xz")

@soriadelva
Copy link
Collaborator Author

save(your_r_object,file="your_rda_file.rda",compress="xz")

This works, grazie!

@damianooldoni
Copy link
Collaborator

You are welcome. I see a lot of notes. Most of them are typically due to the fact that while developing a package, you cannot just use df %>% dplyr::select(col1, col2) but df %>% dplyr::select("col1", "col2"), same holds true for dplyr::rename() and dplyr::relocate(), i.e. all functions using tidyselect under the hood.
All other dplyr functions, like dplyr::filter() should use the .data$ prefix, e.g. df %>% dplyr::filter(.data$col1 > 0) or df %>% dplyr::mutate(newcol = .data$col1 +1) or df %>% dplyr::group_by(.data$col1).

Can you do a screening on climate_match.R first? Then I will review and I will push some other changes if I see I can solve some of the notes.

In any case, we are near to merge 🥳

@soriadelva
Copy link
Collaborator Author

soriadelva commented Apr 22, 2024

You are welcome. I see a lot of notes. Most of them are typically due to the fact that while developing a package, you cannot just use df %>% dplyr::select(col1, col2) but df %>% dplyr::select("col1", "col2"), same holds true for dplyr::rename() and dplyr::relocate(), i.e. all functions using tidyselect under the hood. All other dplyr functions, like dplyr::filter() should use the .data$ prefix, e.g. df %>% dplyr::filter(.data$col1 > 0) or df %>% dplyr::mutate(newcol = .data$col1 +1) or df %>% dplyr::group_by(.data$col1).

Can you do a screening on climate_match.R first? Then I will review and I will push some other changes if I see I can solve some of the notes.

In any case, we are near to merge 🥳

@damianooldoni, I fixed all notes except those that are related to the .rda files in the /data folder. Example:
climate_match: no visible binding for global variable 'legends'. legends is successfully loaded with devtools::load_all() and the documentation under the /R folder is all in place, but still devtools::check() does not seem to recognize this dataset properly. The same problem exists for the other .rda files in that folder. Would you know how to solve this? This question has already been asked on Stackoverflow (I checked the one response, but the problem does not seem to be the documentation): https://stackoverflow.com/questions/64195806/rnote-no-visible-binding-for-global-variable-after-devtoolsuse-data

This is done to solve the NOTE  that pops up when running devtools::check()
@soriadelva
Copy link
Collaborator Author

@damianooldoni, okay to merge? :)

Copy link
Contributor

@SanderDevisscher SanderDevisscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok for me

@damianooldoni
Copy link
Collaborator

Thanks @soriadelva. I will try my best to check all of this during the afternoon.

@soriadelva
Copy link
Collaborator Author

soriadelva commented Apr 24, 2024

Thanks @soriadelva. I will try my best to check all of this during the afternoon.

Thanks @damianooldoni ! and no worries, you'll see when you have time!

@damianooldoni
Copy link
Collaborator

Sorry, @soriadelva. I was very busy with the preparation of the coding club of today. I will try to do it this evening.

@soriadelva
Copy link
Collaborator Author

Sorry, @soriadelva. I was very busy with the preparation of the coding club of today. I will try to do it this evening.

@damianooldoni no worries at all (sorry, I didn't mean to hurry you up!).

soriadelva and others added 5 commits April 25, 2024 14:19
This should solve some warnings returned by the actions, e.g;
Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/checkout@v2. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.
@soriadelva was still not in the list as author.
Copy link
Collaborator

@damianooldoni damianooldoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't solved the global variable undefined for the three built-in data objects used in climate_match function. But I removed some other similar notes and updated the versions of actions in the github workflows.
And the most important stuff: I added @soriadelva as author of the package 👏 congrats!

Let's merge now.

@soriadelva
Copy link
Collaborator Author

I didn't solved the global variable undefined for the three built-in data objects used in climate_match function. But I removed some other similar notes and updated the versions of actions in the github workflows. And the most important stuff: I added @soriadelva as author of the package 👏 congrats!

Let's merge now.

Thanks @damianooldoni 😃

@soriadelva soriadelva merged commit 52edbc6 into main Apr 26, 2024
6 checks passed
@soriadelva soriadelva deleted the 110-rewrite-code-avoiding-using-sp-and-rworldmap branch April 26, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

rewrite code avoiding using sp and rworldmap
3 participants