Skip to content

Commit

Permalink
dataset_bibentry() function
Browse files Browse the repository at this point in the history
  • Loading branch information
antaldaniel committed Nov 17, 2023
1 parent 4867fe6 commit 4057ae3
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export(creator)
export(datacite)
export(datacite_add)
export(dataset)
export(dataset_bibentry)
export(dataset_download)
export(dataset_export)
export(dataset_export_csv)
Expand Down
2 changes: 0 additions & 2 deletions R/dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,3 @@ summary.dataset <- function(object, ...) {
cat(paste0("Further metadata: describe(", deparse(substitute(object)), ")\n"))
}



31 changes: 31 additions & 0 deletions R/dataset_bibentry.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' @title Get the bibliographic entries of a dataset
#' @description A dataset constructed with \code{\link{dataset}} records most of the
#' dataset-level metadata in an bibentry object, which allows the printing or saving
#' the bibliographic record in HTML, BibLatex and other formats.
#' For further information on
#' the \code{bibentry} class see \code{utils::\link[utils]{bibentry}}.
#' @param ds A dataset object created by \code{\link{dataset}}.
#' @return The \code{\link[utils]{bibentry}} object of the dataset.
#' @importFrom utils bibentry
#' @examples
#' ds <- dataset(iris,
#' title = "The iris Dataset",
#' author = c(
#' person(family ="Anderson",
#' given ="Edgar",
#' role = "aut")
#' ),
#' identifier = "https://doi.org/10.1111/j.1469-1809.1936.tb02137.x",
#' year = "1935",
#' version = "1.0",
#' description = "The famous dataset that is distributed with R.",
#' url = "https://en.wikipedia.org/wiki/Iris_flower_data_set",
#' resourceType = "Dataset"
#' )
#' print(ds, style="text")
#' print(ds, style="Bibtex")
#' @export

dataset_bibentry <- function(ds) {
attr(ds, "DataBibentry")
}
39 changes: 39 additions & 0 deletions man/dataset_bibentry.Rd

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

18 changes: 18 additions & 0 deletions tests/testthat/test-dataset_bibentry.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ds <- dataset(iris,
title = "The iris Dataset",
author = c(
person(family ="Anderson",
given ="Edgar",
role = "aut")
),
identifier = "https://doi.org/10.1111/j.1469-1809.1936.tb02137.x",
year = "1935",
version = "1.0",
description = "The famous dataset that is distributed with R.",
url = "https://en.wikipedia.org/wiki/Iris_flower_data_set",
resourceType = "Dataset"
)

test_that("multiplication works", {
expect_equal(class(dataset_bibentry(ds)), "bibentry")
})

0 comments on commit 4057ae3

Please sign in to comment.