Skip to content

Commit

Permalink
Merge pull request #87 from trias-project/return-data-slots
Browse files Browse the repository at this point in the history
Return data slots
  • Loading branch information
damianooldoni authored Jun 10, 2022
2 parents 6c81b63 + 5976058 commit 5d52674
Show file tree
Hide file tree
Showing 14 changed files with 320 additions and 242 deletions.
51 changes: 24 additions & 27 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,48 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
## uncomment when updated terra binaries are ready
# - {os: macOS-latest, r: 'release'}
# - {os: windows-latest, r: 'release'}
- {os: ubuntu-18.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest", http-user-agent: "R/4.0.0 (ubuntu-18.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" }
- {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
- {os: ubuntu-18.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
_R_CHECK_SYSTEM_CLOCK_: false
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GH_PAT }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
ORCID_TOKEN: ${{ secrets.ORCID_TOKEN }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1
id: install-r
- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-pandoc@master

- name: Install pak and query dependencies
- name: Query dependencies
run: |
install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")
saveRDS(pak::pkg_deps("local::.", dependencies = TRUE), ".github/r-depends.rds")
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ matrix.config.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-${{ hashFiles('.github/r-depends.rds') }}
restore-keys: ${{ matrix.config.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
pak::local_system_requirements(execute = TRUE)
pak::pkg_system_requirements("rcmdcheck", execute = TRUE)
shell: Rscript {0}
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
sudo -s eval "$sysreqs"
- name: Install dependencies
run: |
pak::local_install_dev_deps(upgrade = TRUE)
pak::pkg_install("rcmdcheck")
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Session info
Expand All @@ -82,9 +80,7 @@ jobs:
- name: Check
env:
_R_CHECK_CRAN_INCOMING_: false
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check")
shell: Rscript {0}

- name: Show testthat output
Expand All @@ -94,7 +90,8 @@ jobs:

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
uses: actions/upload-artifact@master
with:
name: ${{ matrix.config.os }}-r${{ matrix.config.r }}-results
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
retention-days: 5
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: trias
Title: Process Data for the Project Tracking Invasive Alien Species
(TrIAS)
Version: 1.6.0
Version: 2.0.0
Authors@R:
c(person(given = "Damiano",
family = "Oldoni",
Expand Down Expand Up @@ -70,4 +70,4 @@ Encoding: UTF-8
LazyData: true
LazyDataCompression: bzip2
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.0
12 changes: 0 additions & 12 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ importFrom(dplyr,case_when)
importFrom(dplyr,count)
importFrom(dplyr,desc)
importFrom(dplyr,distinct)
importFrom(dplyr,distinct_)
importFrom(dplyr,do)
importFrom(dplyr,enquo)
importFrom(dplyr,filter)
importFrom(dplyr,filter_at)
Expand All @@ -47,7 +45,6 @@ importFrom(dplyr,if_else)
importFrom(dplyr,inner_join)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,mutate_all)
importFrom(dplyr,mutate_if)
importFrom(dplyr,n)
importFrom(dplyr,n_distinct)
Expand All @@ -60,28 +57,24 @@ importFrom(dplyr,select)
importFrom(dplyr,starts_with)
importFrom(dplyr,summarize)
importFrom(dplyr,sym)
importFrom(dplyr,syms)
importFrom(dplyr,tally)
importFrom(dplyr,tibble)
importFrom(dplyr,ungroup)
importFrom(dplyr,vars)
importFrom(egg,ggarrange)
importFrom(forcats,fct_rev)
importFrom(ggplot2,aes)
importFrom(ggplot2,coord_cartesian)
importFrom(ggplot2,coord_flip)
importFrom(ggplot2,element_text)
importFrom(ggplot2,facet_wrap)
importFrom(ggplot2,geom_bar)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_ribbon)
importFrom(ggplot2,geom_smooth)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggsave)
importFrom(ggplot2,ggtitle)
importFrom(ggplot2,scale_colour_manual)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme)
importFrom(ggplot2,xlab)
Expand All @@ -104,13 +97,10 @@ importFrom(mgcv,nb)
importFrom(mgcv,summary.gam)
importFrom(plotly,ggplotly)
importFrom(plotly,layout)
importFrom(purrr,cross_df)
importFrom(purrr,list_along)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map2_chr)
importFrom(purrr,map_chr)
importFrom(purrr,map_df)
importFrom(purrr,map_dfr)
importFrom(purrr,pmap_dfr)
importFrom(purrr,reduce)
Expand Down Expand Up @@ -155,8 +145,6 @@ importFrom(stringr,str_to_lower)
importFrom(svDialogs,dlgInput)
importFrom(tibble,as_tibble)
importFrom(tibble,tibble)
importFrom(tidyr,gather)
importFrom(tidyr,unnest)
importFrom(tidyselect,all_of)
importFrom(tidyselect,ends_with)
importFrom(tidyselect,one_of)
Expand Down
19 changes: 8 additions & 11 deletions R/gbif_has_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
#' occurrenceStatus) and establishmentMeans.
#' @return a logical, TRUE or FALSE.
#' @export
#' @importFrom assertthat assert_that
#' @importFrom rgbif name_usage
#' @importFrom dplyr select %>% distinct_ mutate_all
#' @importFrom purrr map cross_df
#' @importFrom dplyr %>%
#' @examples
#' # numeric taxonKey, atomic parameters
#' gbif_has_distribution(145953242,
Expand All @@ -38,7 +35,7 @@
#'
#' # Case insensitive
#' gbif_has_distribution("145953242",
#' countryCode = "be",
#' country = "be",
#' status = "PRESENT",
#' establishmentMeans = "InTrOdUcEd"
#' )
Expand Down Expand Up @@ -115,15 +112,15 @@ gbif_has_distribution <- function(taxon_key, ...) {
return(FALSE)
} else {
# Avoid mismatch due to any upper/lowercase difference
user_properties <- map(user_properties, ~ toupper(.))
# Check whether at least
user_properties <- purrr::map(user_properties, ~ toupper(.))
# Check whether at least one property defined by user is present
has_distr <- dplyr::intersect(
user_properties %>%
cross_df(),
purrr::cross_df(),
distr_properties %>%
select(names(user_properties)) %>%
distinct_(.dots = names(user_properties)) %>%
mutate_all(toupper)
dplyr::select(names(user_properties)) %>%
dplyr::distinct() %>%
dplyr::mutate(dplyr::across(.cols = everything(), toupper))
) %>%
nrow() > 0
return(has_distr)
Expand Down
49 changes: 22 additions & 27 deletions R/gbif_verify_keys.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@
#' \code{NA} for other two columns. If a key didn't pass the second check
#' (\code{is_from_gbif_backbone = FALSE}) then \code{is_synonym} = \code{NA}.
#' @export
#' @importFrom assertthat assert_that
#' @importFrom dplyr pull mutate filter left_join full_join select .data enquo
#' @importFrom purrr reduce map_df
#' @importFrom rgbif name_usage
#' @importFrom dplyr .data %>%
#' @importFrom rlang !!
#' @importFrom tidyr gather
#' @importFrom tidyselect vars_pull
#' @examples
#' # input is a vector
#' keys1 <- c(
Expand Down Expand Up @@ -70,36 +65,36 @@
#' gbif_verify_keys(keys3)
#' gbif_verify_keys(keys4)
gbif_verify_keys <- function(keys, col_keys = "key") {
assert_that(is.data.frame(keys) | is.vector(keys),
assertthat::assert_that(is.data.frame(keys) | is.vector(keys),
msg = "keys should be a vector, a named list or a data.frame."
)
if (is.data.frame(keys)) {
assert_that(col_keys %in% names(keys),
assertthat::assert_that(col_keys %in% names(keys),
msg = paste(
"Column with keys not found.",
"Did you forget maybe to pass",
"the right column name to col_keys?"
)
)
name_col <- vars_pull(names(keys), !!enquo(col_keys))
name_col <- tidyselect::vars_pull(names(keys), !!dplyr::enquo(col_keys))
# extract vector of keys from df
keys <-
keys %>%
pull(name_col)
dplyr::pull(name_col)
}
keys <- keys[!is.na(keys)]
if (length(keys) == 0 | isTRUE(all(keys == ""))) {
return(NULL)
} else {
assert_that(all(keys != "") == TRUE,
assertthat::assert_that(all(keys != "") == TRUE,
msg = paste(
"Invalid keys:",
paste(rep("\"\"\"\"", length(keys[which(keys == "")])),
collapse = ","
), "."
)
)
assert_that(all(!grepl("\\D", keys)) == TRUE,
assertthat::assert_that(all(!grepl("\\D", keys)) == TRUE,
msg = paste(
"Invalid keys:",
paste(keys[which(!grepl("\\D", keys) == FALSE)],
Expand All @@ -116,58 +111,58 @@ gbif_verify_keys <- function(keys, col_keys = "key") {
names(keys) <- as.character(keys)
gbif_info <-
keys %>%
map(~ tryCatch(name_usage(.)$data[1, ],
purrr::map(~ tryCatch(rgbif::name_usage(.)$data[1, ],
error = function(e) {
print(paste("Key", ., "is an invalid GBIF taxon key."))
}
))
check_keys <-
map_df(gbif_info, ~ is.character(.) == FALSE)
purrr::map_df(gbif_info, ~ is.character(.) == FALSE)
check_keys <-
check_keys %>%
gather(key = "key", value = "is_taxonKey") %>%
mutate(key = as.numeric(.data$key))
tidyr::gather(key = "key", value = "is_taxonKey") %>%
dplyr::mutate(key = as.numeric(.data$key))
valid_keys_df <-
check_keys %>%
filter(.data$is_taxonKey == TRUE)
dplyr::filter(.data$is_taxonKey == TRUE)
valid_keys <- gbif_info[which(names(gbif_info) %in% valid_keys_df$key)]
if (length(valid_keys) > 0) {
valid_keys_df <-
valid_keys %>%
reduce(bind_rows) %>%
mutate(is_from_gbif_backbone = ifelse(.data$datasetKey == uuid_backbone,
purrr::reduce(bind_rows) %>%
dplyr::mutate(is_from_gbif_backbone = ifelse(.data$datasetKey == uuid_backbone,
TRUE, FALSE
))
check_keys <-
check_keys %>%
left_join(valid_keys_df %>%
select(.data$key, .data$is_from_gbif_backbone),
dplyr::left_join(valid_keys_df %>%
dplyr::select(.data$key, .data$is_from_gbif_backbone),
by = "key"
)
valid_keys_df <-
valid_keys_df %>%
filter(.data$is_from_gbif_backbone == TRUE) %>%
mutate(is_synonym = ifelse(!.data$taxonomicStatus %in% c("ACCEPTED", "DOUBTFUL"),
dplyr::filter(.data$is_from_gbif_backbone == TRUE) %>%
dplyr::mutate(is_synonym = ifelse(!.data$taxonomicStatus %in% c("ACCEPTED", "DOUBTFUL"),
TRUE, FALSE
))
check_keys <-
check_keys %>%
left_join(valid_keys_df %>%
select(.data$key, .data$is_synonym),
dplyr::left_join(valid_keys_df %>%
dplyr::select(.data$key, .data$is_synonym),
by = "key"
)
} else {
check_keys <-
check_keys %>%
mutate(
dplyr::mutate(
is_from_gbif_backbone = NA,
is_synonym = NA
)
}

# recreate possible duplicates by joining input_keys_df with check_keys
input_keys_df %>%
left_join(check_keys,
dplyr::left_join(check_keys,
by = "key")
}

Expand Down
Loading

0 comments on commit 5d52674

Please sign in to comment.