From 0cb07c92e991478fe66c73182567fbe3846de50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 9 Apr 2018 16:18:52 +0200 Subject: [PATCH] cf #63 --- R/codemeta_description.R | 23 ++++++++++++++--- inst/examples/DESCRIPTION_Rforge | 29 ++++++++++++++++++++++ inst/examples/DESCRIPTION_no_URL | 28 +++++++++++++++++++++ inst/examples/DESCRIPTION_no_bugreports | 28 +++++++++++++++++++++ inst/examples/DESCRIPTION_two_URLs | 29 ++++++++++++++++++++++ tests/testthat/test-codemeta_description.R | 22 ++++++++++++++-- 6 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 inst/examples/DESCRIPTION_Rforge create mode 100644 inst/examples/DESCRIPTION_no_URL create mode 100644 inst/examples/DESCRIPTION_no_bugreports create mode 100644 inst/examples/DESCRIPTION_two_URLs diff --git a/R/codemeta_description.R b/R/codemeta_description.R index a7bc44ee..3250aa72 100644 --- a/R/codemeta_description.R +++ b/R/codemeta_description.R @@ -38,9 +38,26 @@ codemeta_description <- descr$get("Title")) - ## Will later guess these these a la devtools::use_github_links - codemeta$codeRepository <- descr$get("URL") - codemeta$issueTracker <- descr$get("BugReports") + ## Enforce good practice + code_repo <- descr$get_urls() + if (!is.na(code_repo[1])){ + if(length(code_repo) == 1){ + codemeta$codeRepository <- code_repo + }else{ + codemeta$codeRepository <- code_repo[grepl("github\\.com", code_repo)| + grepl("gitlab\\.com", code_repo)][1] + } + }else{ + stop("Please enter a valid URL field in DESCRIPION") + } + + issue_tracker <- descr$get("BugReports") + if (!is.na(issue_tracker)){ + codemeta$issueTracker <- issue_tracker + }else{ + warning("Please enter a valid issueTracker field in DESCRIPION") + } + ## According to crosswalk, codemeta$dateModified and diff --git a/inst/examples/DESCRIPTION_Rforge b/inst/examples/DESCRIPTION_Rforge new file mode 100644 index 00000000..5bf2a4fa --- /dev/null +++ b/inst/examples/DESCRIPTION_Rforge @@ -0,0 +1,29 @@ +Package: essurvey +Title: Download Data from the European Social Survey on the Fly +Version: 1.0.0 +Authors@R: c( + person("Jorge", "Cimentada", email = "cimentadaj@gmail.com", role = c("aut", "cre")), + person("Thomas", "Leeper", role = "rev", comment = "Thomas reviewed the package for rOpensci,see https://github.com/ropensci/onboarding/issues/201"), + person("Nujcharee", "Haswell", role = "rev", comment = "Nujcharee reviewed the package for rOpensci, see https://github.com/ropensci/onboarding/issues/201") + ) +BugReports: https://github.com/ropensci/essurvey/issues +Description: Download data from the European Social Survey directly from their website . There are two families of functions that allow you to download and interactively check all countries and rounds available. +Depends: R (>= 3.4.0) +License: MIT + file LICENSE +URL: http://surveillance.R-Forge.R-project.org/ +Encoding: UTF-8 +LazyData: true +RoxygenNote: 6.0.1 +Imports: + xml2, + httr, + stringr, + haven, + rvest, + tibble +Suggests: + testthat, + knitr, + rmarkdown, + covr +VignetteBuilder: knitr diff --git a/inst/examples/DESCRIPTION_no_URL b/inst/examples/DESCRIPTION_no_URL new file mode 100644 index 00000000..f0d23904 --- /dev/null +++ b/inst/examples/DESCRIPTION_no_URL @@ -0,0 +1,28 @@ +Package: essurvey +Title: Download Data from the European Social Survey on the Fly +Version: 1.0.0 +Authors@R: c( + person("Jorge", "Cimentada", email = "cimentadaj@gmail.com", role = c("aut", "cre")), + person("Thomas", "Leeper", role = "rev", comment = "Thomas reviewed the package for rOpensci,see https://github.com/ropensci/onboarding/issues/201"), + person("Nujcharee", "Haswell", role = "rev", comment = "Nujcharee reviewed the package for rOpensci, see https://github.com/ropensci/onboarding/issues/201") + ) +BugReports: https://github.com/ropensci/essurvey/issues +Description: Download data from the European Social Survey directly from their website . There are two families of functions that allow you to download and interactively check all countries and rounds available. +Depends: R (>= 3.4.0) +License: MIT + file LICENSE +Encoding: UTF-8 +LazyData: true +RoxygenNote: 6.0.1 +Imports: + xml2, + httr, + stringr, + haven, + rvest, + tibble +Suggests: + testthat, + knitr, + rmarkdown, + covr +VignetteBuilder: knitr diff --git a/inst/examples/DESCRIPTION_no_bugreports b/inst/examples/DESCRIPTION_no_bugreports new file mode 100644 index 00000000..d8c0c08a --- /dev/null +++ b/inst/examples/DESCRIPTION_no_bugreports @@ -0,0 +1,28 @@ +Package: essurvey +Title: Download Data from the European Social Survey on the Fly +Version: 1.0.0 +Authors@R: c( + person("Jorge", "Cimentada", email = "cimentadaj@gmail.com", role = c("aut", "cre")), + person("Thomas", "Leeper", role = "rev", comment = "Thomas reviewed the package for rOpensci,see https://github.com/ropensci/onboarding/issues/201"), + person("Nujcharee", "Haswell", role = "rev", comment = "Nujcharee reviewed the package for rOpensci, see https://github.com/ropensci/onboarding/issues/201") + ) +Description: Download data from the European Social Survey directly from their website . There are two families of functions that allow you to download and interactively check all countries and rounds available. +Depends: R (>= 3.4.0) +License: MIT + file LICENSE +URL: https://github.com/ropensci/essurvey, https://ropensci.github.io/essurvey/ +Encoding: UTF-8 +LazyData: true +RoxygenNote: 6.0.1 +Imports: + xml2, + httr, + stringr, + haven, + rvest, + tibble +Suggests: + testthat, + knitr, + rmarkdown, + covr +VignetteBuilder: knitr diff --git a/inst/examples/DESCRIPTION_two_URLs b/inst/examples/DESCRIPTION_two_URLs new file mode 100644 index 00000000..2c32fe91 --- /dev/null +++ b/inst/examples/DESCRIPTION_two_URLs @@ -0,0 +1,29 @@ +Package: essurvey +Title: Download Data from the European Social Survey on the Fly +Version: 1.0.0 +Authors@R: c( + person("Jorge", "Cimentada", email = "cimentadaj@gmail.com", role = c("aut", "cre")), + person("Thomas", "Leeper", role = "rev", comment = "Thomas reviewed the package for rOpensci,see https://github.com/ropensci/onboarding/issues/201"), + person("Nujcharee", "Haswell", role = "rev", comment = "Nujcharee reviewed the package for rOpensci, see https://github.com/ropensci/onboarding/issues/201") + ) +BugReports: https://github.com/ropensci/essurvey/issues +Description: Download data from the European Social Survey directly from their website . There are two families of functions that allow you to download and interactively check all countries and rounds available. +Depends: R (>= 3.4.0) +License: MIT + file LICENSE +URL: https://github.com/ropensci/essurvey, https://ropensci.github.io/essurvey/ +Encoding: UTF-8 +LazyData: true +RoxygenNote: 6.0.1 +Imports: + xml2, + httr, + stringr, + haven, + rvest, + tibble +Suggests: + testthat, + knitr, + rmarkdown, + covr +VignetteBuilder: knitr diff --git a/tests/testthat/test-codemeta_description.R b/tests/testthat/test-codemeta_description.R index f3d026d2..69863210 100644 --- a/tests/testthat/test-codemeta_description.R +++ b/tests/testthat/test-codemeta_description.R @@ -5,8 +5,26 @@ testthat::test_that("We can use a preset id", { codemeta_description(f, id = "https://doi.org/10.looks.like/doi") }) -testthat::test_that("We can parse plain Authors: & Maintainers: entries", { - f <- system.file("examples/DESCRIPTION_ex1.dcf", package = "codemetar") +testthat::test_that("Error if no URL", { + f <- system.file("examples/DESCRIPTION_no_URL", package = "codemetar") expect_error(codemeta_description(f)) }) +testthat::test_that("Warning if no BugReports", { + f <- system.file("examples/DESCRIPTION_Rforge", package = "codemetar") + cm <- codemeta_description(f) + expect_equal(cm$codeRepository, "http://surveillance.R-Forge.R-project.org/") +}) + +testthat::test_that("Works R-forge", { + f <- system.file("examples/DESCRIPTION_two_URLs", package = "codemetar") + cm <- codemeta_description(f) + expect_equal(cm$codeRepository, "https://github.com/ropensci/essurvey") +}) + + + +testthat::test_that("Choose GitHub", { + f <- system.file("examples/DESCRIPTION_ex1.dcf", package = "codemetar") + expect_error(codemeta_description(f)) +})