Skip to content

Commit b7871cc

Browse files
authored
Merge pull request #346 from ropensci/i345-responsiblePartyOrganizations
Allow set_responsibleParty to create organizations
2 parents b859f31 + bd64e16 commit b7871cc

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

R/set_responsibleParty.R

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@
1616
#' @export
1717
#'
1818
#' @examples
19+
#' # Pass in either a person object or separate values to create an individual
1920
#' carl <- set_responsibleParty(as.person("Carl Boettiger <[email protected]>"))
2021
#' matt <- set_responsibleParty("Matthew", "Jones", email = "mbjones@@nceas.ucsb.edu")
22+
#'
23+
#' # To create an organization, used the named `organization` argument to
24+
#' specify the organization name
25+
#' my_org <- set_responsibleParty(
26+
#' organization = "My Organization",
27+
#' email = "[email protected]"
28+
#' )
2129
set_responsibleParty <-
2230
function(givenName = NULL,
2331
surName = NULL,
@@ -30,8 +38,13 @@ set_responsibleParty <-
3038
userId = NULL,
3139
id = NULL,
3240
email = NULL) {
33-
UseMethod("set_responsibleParty", givenName)
34-
}
41+
42+
if (is(givenName, "person")) {
43+
UseMethod("set_responsibleParty", givenName)
44+
} else {
45+
UseMethod("set_responsibleParty", c(surName, organizationName))
46+
}
47+
}
3548

3649
#' @export
3750
set_responsibleParty.person <- function(givenName, ...) {

tests/testthat/test-set_responsibleParty.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,24 @@ testthat::test_that("We can set responsible party", {
2121
testthat::expect_true(eml_validate("ex.xml"))
2222
unlink("ex.xml")
2323
})
24+
25+
testthat::test_that("We can set a responsible party that's an organization", {
26+
# Verify this way of calling the function works
27+
party <- set_responsibleParty(organizationName = "Some Organization")
28+
testthat::expect_equal(party$organizationName, "Some Organization")
29+
30+
# Also verify we create valid documents when doing so
31+
doc <- list(
32+
dataset = list(
33+
title = "dataset title",
34+
contact = party,
35+
creator = party
36+
),
37+
system = "doi",
38+
packageId = "10.xxx"
39+
)
40+
41+
write_eml(doc, "ex.xml")
42+
testthat::expect_true(eml_validate("ex.xml"))
43+
unlink("ex.xml")
44+
})

0 commit comments

Comments
 (0)