Skip to content

Commit

Permalink
added generate_citation()
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterprovoost committed Aug 6, 2022
1 parent ac3c2b4 commit c80af7a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
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.10.1
Date: 2022-01-26
Version: 2.11.0
Date: 2022-08-06
Authors@R: c(
person("Pieter", "Provoost", , "[email protected]", c("cre", "aut")),
person("Samuel", "Bosch", , "[email protected]", role = "aut"),
Expand Down Expand Up @@ -30,7 +30,8 @@ Imports:
curl,
data.table,
tidyselect,
xml2
xml2,
glue
Collate:
robis.R
util.R
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(area)
export(checklist)
export(dataset)
export(dna_records)
export(generate_citation)
export(get_geometry)
export(map_ggplot)
export(map_leaflet)
Expand All @@ -14,6 +15,7 @@ export(taxon)
export(unnest_extension)
import(dplyr)
import(ggplot2)
import(glue)
import(httr)
import(jsonlite)
import(leaflet)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# rovis 2.11.0

Added `generate_citation()`.

# robis 2.10.1

Added contacts to `dataset()`.
Expand Down
2 changes: 1 addition & 1 deletion R/robis.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#'
#' @docType package
#' @name robis
#' @import dplyr jsonlite leaflet ggplot2 tidyr tibble httr mapedit sf stringr tidyselect xml2
#' @import dplyr jsonlite leaflet ggplot2 tidyr tibble httr mapedit sf stringr tidyselect xml2 glue
#' @importFrom rlang .data
#' @importFrom curl has_internet
#' @importFrom data.table as.data.table
Expand Down
26 changes: 26 additions & 0 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,29 @@ unnest_extension <- function(df, extension, fields = "id") {
}
}
}

#' Generate a citation from metadata elements.
#'
#' @usage generate_citation(title, published, url, contacts)
#' @param title the dataset title.
#' @param published the dataset published date.
#' @param url the dataset url.
#' @param contacts the dataset contacts as a dataframe.
#' @return A citation string.
#' @export
generate_citation <- function(title, published, url, contacts) {
title <- gsub("\\.$", "", title)
published <- substr(published, 1, 10)
url <- url
names_list <- contacts %>%
select(givenname, surname, organization) %>%
distinct() %>%
arrange(surname) %>%
mutate(givenname = ifelse(!is.na(givenname), paste0(substr(givenname, 1, 1), "."), NA)) %>%
rowwise() %>%
mutate(name = ifelse(is.na(surname), organization, paste0(na.omit(c(surname, givenname)), collapse = ", "))) %>%
pull(name) %>%
paste0(collapse = ", ")
names_list <- gsub("\\.$", "", names_list)
glue("{names_list}. {title}. Published {published}. {url}.")
}
23 changes: 23 additions & 0 deletions man/generate_citation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c80af7a

Please sign in to comment.