-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e601bd
commit 02544b4
Showing
10 changed files
with
110 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Package: robis | ||
Title: Ocean Biodiversity Information System (OBIS) Client | ||
Description: Client for the Ocean Biodiversity Information System (<https://obis.org>). | ||
Version: 2.7.2 | ||
Date: 2021-09-24 | ||
Version: 2.8.0 | ||
Date: 2021-09-27 | ||
Authors@R: c( | ||
person("Pieter", "Provoost", , "[email protected]", c("cre", "aut")), | ||
person("Samuel", "Bosch", , "[email protected]", role = "aut"), | ||
|
@@ -29,7 +29,20 @@ Imports: | |
stringr, | ||
curl, | ||
data.table, | ||
tidyselect | ||
tidyselect, | ||
xml2 | ||
Collate: | ||
robis.R | ||
util.R | ||
area.R | ||
checklist.R | ||
dataset.R | ||
dna.R | ||
map.R | ||
mof.R | ||
node.R | ||
occurrence.R | ||
taxon.R | ||
License: MIT + file LICENSE | ||
Suggests: | ||
testthat, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
utils::globalVariables("where") | ||
|
||
dna_cols <- get_dwc_fields("https://rs.gbif.org/extension/gbif/1.0/dna_derived_data_2021-07-05.xml") | ||
|
||
fast_unnest_dna <- function(dt, cols) { | ||
dna <- NULL | ||
dt[, unlist(dna, recursive = FALSE), by = mget(cols)] | ||
} | ||
|
||
clean_dna_table <- function(m) { | ||
if (is.data.frame(m)) { | ||
m <- m %>% | ||
select(where(~!all(is.na(.x)))) | ||
missing_cols <- setdiff(dna_cols, names(m)) | ||
m[missing_cols] <- as.character(NA) | ||
m %>% | ||
select(all_of(c(dna_cols, "level"))) | ||
} else { | ||
NULL | ||
} | ||
} | ||
|
||
#' Extract DNA records from occurrence data with a dna column. | ||
#' | ||
#' @usage dna_records(df, fields = "id") | ||
#' @param df the occurrence dataframe. | ||
#' @param fields columns from the occurrence dataframe to include. | ||
#' @return The DNA records. | ||
#' @export | ||
dna_records <- function(df, fields = "id") { | ||
dna <- NULL | ||
fields <- unique(c("id", fields)) | ||
if ("id" %in% names(df) & "dna" %in% names(df)) { | ||
if (class(df$dna) == "list") { | ||
dt <- df %>% | ||
select(all_of(c(fields, "dna"))) %>% | ||
filter(!sapply(.data$dna, is.null)) %>% | ||
mutate(dna = lapply(dna, clean_dna_table)) %>% | ||
as.data.table() | ||
dt %>% | ||
fast_unnest_dna(fields) %>% | ||
as_tibble() | ||
} else { | ||
tibble() | ||
} | ||
} else { | ||
warning("Missing columns id or dna") | ||
NULL | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.