From d24659c4bc9f339f0b0a84305f2cc419bf86a56e Mon Sep 17 00:00:00 2001 From: Bai Li Date: Thu, 6 Oct 2022 14:52:21 -0400 Subject: [PATCH 1/7] update documentation and add validate_Rd function --- DESCRIPTION | 5 ++-- NAMESPACE | 2 ++ R/validate_Rd.R | 72 ++++++++++++++++++++++++++++++++++++++++++++++ man/Biomass.Rd | 3 +- man/Forecast.Rd | 2 +- man/Projection.Rd | 24 ++++++++++++++++ man/add_object.Rd | 7 +++-- man/validate_Rd.Rd | 20 +++++++++++++ 8 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 R/validate_Rd.R create mode 100644 man/Projection.Rd create mode 100644 man/validate_Rd.Rd diff --git a/DESCRIPTION b/DESCRIPTION index c95280b..3fd376e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,6 +9,7 @@ License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a license Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.0.9000 +RoxygenNote: 7.2.1 Imports: - mvbutils + mvbutils, + tools diff --git a/NAMESPACE b/NAMESPACE index 60495e0..bd3aacd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,3 +7,5 @@ export(Weight) export(add_object) export(read_in) export(shiny_dd) +export(validate_Rd) +import(tools) diff --git a/R/validate_Rd.R b/R/validate_Rd.R new file mode 100644 index 0000000..f771ea5 --- /dev/null +++ b/R/validate_Rd.R @@ -0,0 +1,72 @@ +#' Function to validate terms in the dictionary. +#' +#' The dictionary terms are written in R documentation (Rd) format. +#' This function reads the Rd file using the `tools::parse_Rd` function +#' validate the information in each section (e.g., examples, rationale, +#' range of possible values, etc.). +#' +#' @param Rd_file a Rd filename to use as input. +#' @return a message if the term passes all validations. +#' @import tools +#' @export +validate_Rd <- function(Rd_file) { + if (is.null(Rd_file)) stop("Please provide the path to the R documentation (Rd) file.") + + Rd <- tools::parse_Rd(Rd_file) + tags <- tools:::RdTags(Rd) + + # Validate name + name <- Rd[[which(tags == "\\name")]] + if (is.null(name[[1]][1])) stop("Name is not provided. This should be the basename of the Rd file.") + + # Validate title + title <- Rd[[which(tags == "\\title")]] + if (is.null(title[[1]][1])) stop("Title is not provided. Title should be capitalized and not end in a period.") + + # Validate description + description <- Rd[[which(tags == "\\description")]] + if (gsub("[\r\n]", "", description[[2]][1]) == title[[1]][1] | + is.null(description[[1]][1])) { + stop("Description is not provided. This should be capitalized and not end in a period.") + } + + # Extract format section for validating examples, rationale, alternatives, range of possible values, and units + format <- Rd[[which(tags == "\\format")]][[2]] + items <- c("Examples", "Rationale", "Alternatives", "Range of possible values", "Units") + missing_items <- items[!is.element(items, unlist(format))] + if (any(!is.element(items, unlist(format)))) stop(paste("Missing", paste(missing_items, collapse = ", "))) + + # Validate examples + if (format[[2]][[1]][[1]][1] == "Examples" & + length(format[[2]][[2]]) == 0) { + stop("Examples are not provided. Use NA if there is no input for examples.") + } + + # Validate rationale + if (format[[4]][[1]][[1]][1] == "Rationale" & + length(format[[4]][[2]]) == 0) { + stop("Rationale is not provided.") + } + + # Validate alternatives + if (format[[6]][[1]][[1]][1] == "Alternatives" & + length(format[[6]][[2]]) == 0) { + stop("Alternatives are not provided. Use NA if there is no input for alternatives.") + } + + # Validate range of possible values + if (format[[8]][[1]][[1]][1] == "Range of possible values" & + length(format[[8]][[2]]) == 0) { + stop("Range of possible values is not provided. Use NA if there is no input for range of possible values.") + } + + # Validate range of possible values + if (format[[10]][[1]][[1]][1] == "Units" & + length(format[[10]][[2]]) == 0) { + stop("Units are not provided. Use NA if there is no input for units.") + } + + + # Return a message if the term passes all validations + message(paste("Term", name[[1]][1], "has passed all validations!")) +} diff --git a/man/Biomass.Rd b/man/Biomass.Rd index 92793e4..da0fbb7 100644 --- a/man/Biomass.Rd +++ b/man/Biomass.Rd @@ -16,7 +16,8 @@ Additional ambiguity can come from the lack of knowledge regarding the unit of measurement, which should always be metric tons. Some alternatives are not interchangeable because they are in different units, e.g., abundance, which is in terms of numbers rather than weight.} -\item{Alternatives}{stock biomass, total biomass, abundance (numbers of fish), biomass wet weight, biomass index} +\item{Alternatives}{stock biomass, total biomass, abundance (numbers of fish), +biomass wet weight, biomass index} \item{Range of possible values}{0--Inf} \item{Units}{mt} } diff --git a/man/Forecast.Rd b/man/Forecast.Rd index fa144ca..1289f9e 100644 --- a/man/Forecast.Rd +++ b/man/Forecast.Rd @@ -19,6 +19,6 @@ it depends on an assumption about future catches.} Forecast } \description{ -A probabilistic statement about future events. +A probabilistic statement about future events based on what will happen. } \keyword{datasets} diff --git a/man/Projection.Rd b/man/Projection.Rd new file mode 100644 index 0000000..48aedf9 --- /dev/null +++ b/man/Projection.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Projection.R +\docType{data} +\name{Projection} +\alias{Projection} +\title{Projection} +\format{ +\describe{ +\item{Examples}{short-term projection} +\item{Rationale}{Future weather is a forecast because it does not require +an if statement, whereas future spawning biomass is a projection because +it depends on an assumption about future catches.} +\item{Alternatives}{forecast, prediction} +\item{Range of possible values}{} +\item{Units}{} +} +} +\usage{ +Projection +} +\description{ +A probabilistic statement about future events based on what might happen. +} +\keyword{datasets} diff --git a/man/add_object.Rd b/man/add_object.Rd index 5ce1e40..78e4ebd 100644 --- a/man/add_object.Rd +++ b/man/add_object.Rd @@ -4,11 +4,14 @@ \alias{add_object} \title{Function to add an object to the JSON} \usage{ -add_object(json_obj, input_list) +add_object(input_list) } \arguments{ \item{input_list}{A list of fields corresponding to entries. Must include -\code{name,description,Units}} +\code{name,description,Examples, Units, Rationale, Alternatives, Range of possible values}} +} +\value{ +An R list in the JSON format which includes the new term. } \description{ Function to add an object to the JSON diff --git a/man/validate_Rd.Rd b/man/validate_Rd.Rd new file mode 100644 index 0000000..aedea1a --- /dev/null +++ b/man/validate_Rd.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/validate_Rd.R +\name{validate_Rd} +\alias{validate_Rd} +\title{Function to validate terms in the dictionary.} +\usage{ +validate_Rd(Rd_file) +} +\arguments{ +\item{Rd_file}{a Rd filename to use as input.} +} +\value{ +a message if the term passes all validations. +} +\description{ +The dictionary terms are written in R documentation (Rd) format. +This function reads the Rd file using the \code{tools::parse_Rd} function +validate the information in each section (e.g., examples, rationale, +range of possible values, etc.). +} From fb23886b8f366c962ae6d828414fd796d9eaddf4 Mon Sep 17 00:00:00 2001 From: Bai Li Date: Thu, 6 Oct 2022 14:53:25 -0400 Subject: [PATCH 2/7] test: add tests for validate_Rd function --- .../testthat_data/validate_Rd_good_input.Rd | 34 +++++++++++++++++ .../validate_Rd_missing_items.Rd | 25 +++++++++++++ .../validate_Rd_no_alternatives.Rd | 33 +++++++++++++++++ .../validate_Rd_no_description.Rd | 31 ++++++++++++++++ .../testthat_data/validate_Rd_no_examples.Rd | 33 +++++++++++++++++ ...validate_Rd_no_range_of_possible_values.Rd | 34 +++++++++++++++++ .../testthat_data/validate_Rd_no_rationale.Rd | 27 ++++++++++++++ .../testthat_data/validate_Rd_no_units.Rd | 34 +++++++++++++++++ tests/testthat.R | 8 ++++ tests/testthat/test-validate-Rd.R | 37 +++++++++++++++++++ 10 files changed, 296 insertions(+) create mode 100644 inst/extdata/testthat_data/validate_Rd_good_input.Rd create mode 100644 inst/extdata/testthat_data/validate_Rd_missing_items.Rd create mode 100644 inst/extdata/testthat_data/validate_Rd_no_alternatives.Rd create mode 100644 inst/extdata/testthat_data/validate_Rd_no_description.Rd create mode 100644 inst/extdata/testthat_data/validate_Rd_no_examples.Rd create mode 100644 inst/extdata/testthat_data/validate_Rd_no_range_of_possible_values.Rd create mode 100644 inst/extdata/testthat_data/validate_Rd_no_rationale.Rd create mode 100644 inst/extdata/testthat_data/validate_Rd_no_units.Rd create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test-validate-Rd.R diff --git a/inst/extdata/testthat_data/validate_Rd_good_input.Rd b/inst/extdata/testthat_data/validate_Rd_good_input.Rd new file mode 100644 index 0000000..da0fbb7 --- /dev/null +++ b/inst/extdata/testthat_data/validate_Rd_good_input.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Biomass.R +\docType{data} +\name{Biomass} +\alias{Biomass} +\title{Biomass} +\format{ +\describe{ +\item{Examples}{spawning biomass, age three-plus biomass, exploitable +biomass, January 1 biomass} +\item{Rationale}{Measurements of biomass should be better defined making +it clear what year classes and sexes it includes. Historically, verbose +labels, e.g., January 1 biomass of age-three plus fish in 2022, are not +typically used; instead, labels are short, e.g., 2022 3+ biomass. +Additional ambiguity can come from the lack of knowledge regarding the +unit of measurement, which should always be metric tons. Some alternatives +are not interchangeable because they are in different units, e.g., +abundance, which is in terms of numbers rather than weight.} +\item{Alternatives}{stock biomass, total biomass, abundance (numbers of fish), +biomass wet weight, biomass index} +\item{Range of possible values}{0--Inf} +\item{Units}{mt} +} +} +\usage{ +Biomass +} +\description{ +Weight of fish within a stock. If referring to a certain portion of the +stock, it should be made clear what portion of the stock the biomass +pertains to. Model output related to biomass is assumed to be measured +at the beginning of the year unless otherwise specified. +} +\keyword{datasets} diff --git a/inst/extdata/testthat_data/validate_Rd_missing_items.Rd b/inst/extdata/testthat_data/validate_Rd_missing_items.Rd new file mode 100644 index 0000000..154e036 --- /dev/null +++ b/inst/extdata/testthat_data/validate_Rd_missing_items.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Biomass.R +\docType{data} +\name{Biomass} +\alias{Biomass} +\title{Biomass} +\format{ +\describe{ +\item{Examples}{spawning biomass, age three-plus biomass, exploitable +biomass, January 1 biomass} +\item{Alternatives}{stock biomass, total biomass, abundance (numbers of fish), +biomass wet weight, biomass index} +\item{Range of possible values}{0--Inf} +} +} +\usage{ +Biomass +} +\description{ +Weight of fish within a stock. If referring to a certain portion of the +stock, it should be made clear what portion of the stock the biomass +pertains to. Model output related to biomass is assumed to be measured +at the beginning of the year unless otherwise specified. +} +\keyword{datasets} diff --git a/inst/extdata/testthat_data/validate_Rd_no_alternatives.Rd b/inst/extdata/testthat_data/validate_Rd_no_alternatives.Rd new file mode 100644 index 0000000..14b9f44 --- /dev/null +++ b/inst/extdata/testthat_data/validate_Rd_no_alternatives.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Biomass.R +\docType{data} +\name{Biomass} +\alias{Biomass} +\title{Biomass} +\format{ +\describe{ +\item{Examples}{spawning biomass, age three-plus biomass, exploitable +biomass, January 1 biomass} +\item{Rationale}{Measurements of biomass should be better defined making +it clear what year classes and sexes it includes. Historically, verbose +labels, e.g., January 1 biomass of age-three plus fish in 2022, are not +typically used; instead, labels are short, e.g., 2022 3+ biomass. +Additional ambiguity can come from the lack of knowledge regarding the +unit of measurement, which should always be metric tons. Some alternatives +are not interchangeable because they are in different units, e.g., +abundance, which is in terms of numbers rather than weight.} +\item{Alternatives}{} +\item{Range of possible values}{0--Inf} +\item{Units}{mt} +} +} +\usage{ +Biomass +} +\description{ +Weight of fish within a stock. If referring to a certain portion of the +stock, it should be made clear what portion of the stock the biomass +pertains to. Model output related to biomass is assumed to be measured +at the beginning of the year unless otherwise specified. +} +\keyword{datasets} diff --git a/inst/extdata/testthat_data/validate_Rd_no_description.Rd b/inst/extdata/testthat_data/validate_Rd_no_description.Rd new file mode 100644 index 0000000..8fb60e6 --- /dev/null +++ b/inst/extdata/testthat_data/validate_Rd_no_description.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Biomass.R +\docType{data} +\name{Biomass} +\alias{Biomass} +\title{Biomass} +\format{ +\describe{ +\item{Examples}{spawning biomass, age three-plus biomass, exploitable +biomass, January 1 biomass} +\item{Rationale}{Measurements of biomass should be better defined making +it clear what year classes and sexes it includes. Historically, verbose +labels, e.g., January 1 biomass of age-three plus fish in 2022, are not +typically used; instead, labels are short, e.g., 2022 3+ biomass. +Additional ambiguity can come from the lack of knowledge regarding the +unit of measurement, which should always be metric tons. Some alternatives +are not interchangeable because they are in different units, e.g., +abundance, which is in terms of numbers rather than weight.} +\item{Alternatives}{stock biomass, total biomass, abundance (numbers of fish), +biomass wet weight, biomass index} +\item{Range of possible values}{0--Inf} +\item{Units}{mt} +} +} +\usage{ +Biomass +} +\description{ +Biomass +} +\keyword{datasets} diff --git a/inst/extdata/testthat_data/validate_Rd_no_examples.Rd b/inst/extdata/testthat_data/validate_Rd_no_examples.Rd new file mode 100644 index 0000000..2218027 --- /dev/null +++ b/inst/extdata/testthat_data/validate_Rd_no_examples.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Biomass.R +\docType{data} +\name{Biomass} +\alias{Biomass} +\title{Biomass} +\format{ +\describe{ +\item{Examples}{} +\item{Rationale}{Measurements of biomass should be better defined making +it clear what year classes and sexes it includes. Historically, verbose +labels, e.g., January 1 biomass of age-three plus fish in 2022, are not +typically used; instead, labels are short, e.g., 2022 3+ biomass. +Additional ambiguity can come from the lack of knowledge regarding the +unit of measurement, which should always be metric tons. Some alternatives +are not interchangeable because they are in different units, e.g., +abundance, which is in terms of numbers rather than weight.} +\item{Alternatives}{stock biomass, total biomass, abundance (numbers of fish), +biomass wet weight, biomass index} +\item{Range of possible values}{0--Inf} +\item{Units}{mt} +} +} +\usage{ +Biomass +} +\description{ +Weight of fish within a stock. If referring to a certain portion of the +stock, it should be made clear what portion of the stock the biomass +pertains to. Model output related to biomass is assumed to be measured +at the beginning of the year unless otherwise specified. +} +\keyword{datasets} diff --git a/inst/extdata/testthat_data/validate_Rd_no_range_of_possible_values.Rd b/inst/extdata/testthat_data/validate_Rd_no_range_of_possible_values.Rd new file mode 100644 index 0000000..6df97a2 --- /dev/null +++ b/inst/extdata/testthat_data/validate_Rd_no_range_of_possible_values.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Biomass.R +\docType{data} +\name{Biomass} +\alias{Biomass} +\title{Biomass} +\format{ +\describe{ +\item{Examples}{spawning biomass, age three-plus biomass, exploitable +biomass, January 1 biomass} +\item{Rationale}{Measurements of biomass should be better defined making +it clear what year classes and sexes it includes. Historically, verbose +labels, e.g., January 1 biomass of age-three plus fish in 2022, are not +typically used; instead, labels are short, e.g., 2022 3+ biomass. +Additional ambiguity can come from the lack of knowledge regarding the +unit of measurement, which should always be metric tons. Some alternatives +are not interchangeable because they are in different units, e.g., +abundance, which is in terms of numbers rather than weight.} +\item{Alternatives}{stock biomass, total biomass, abundance (numbers of fish), +biomass wet weight, biomass index} +\item{Range of possible values}{} +\item{Units}{mt} +} +} +\usage{ +Biomass +} +\description{ +Weight of fish within a stock. If referring to a certain portion of the +stock, it should be made clear what portion of the stock the biomass +pertains to. Model output related to biomass is assumed to be measured +at the beginning of the year unless otherwise specified. +} +\keyword{datasets} diff --git a/inst/extdata/testthat_data/validate_Rd_no_rationale.Rd b/inst/extdata/testthat_data/validate_Rd_no_rationale.Rd new file mode 100644 index 0000000..8f4badc --- /dev/null +++ b/inst/extdata/testthat_data/validate_Rd_no_rationale.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Biomass.R +\docType{data} +\name{Biomass} +\alias{Biomass} +\title{Biomass} +\format{ +\describe{ +\item{Examples}{spawning biomass, age three-plus biomass, exploitable +biomass, January 1 biomass} +\item{Rationale}{} +\item{Alternatives}{stock biomass, total biomass, abundance (numbers of fish), +biomass wet weight, biomass index} +\item{Range of possible values}{0--Inf} +\item{Units}{mt} +} +} +\usage{ +Biomass +} +\description{ +Weight of fish within a stock. If referring to a certain portion of the +stock, it should be made clear what portion of the stock the biomass +pertains to. Model output related to biomass is assumed to be measured +at the beginning of the year unless otherwise specified. +} +\keyword{datasets} diff --git a/inst/extdata/testthat_data/validate_Rd_no_units.Rd b/inst/extdata/testthat_data/validate_Rd_no_units.Rd new file mode 100644 index 0000000..2de0f73 --- /dev/null +++ b/inst/extdata/testthat_data/validate_Rd_no_units.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Biomass.R +\docType{data} +\name{Biomass} +\alias{Biomass} +\title{Biomass} +\format{ +\describe{ +\item{Examples}{spawning biomass, age three-plus biomass, exploitable +biomass, January 1 biomass} +\item{Rationale}{Measurements of biomass should be better defined making +it clear what year classes and sexes it includes. Historically, verbose +labels, e.g., January 1 biomass of age-three plus fish in 2022, are not +typically used; instead, labels are short, e.g., 2022 3+ biomass. +Additional ambiguity can come from the lack of knowledge regarding the +unit of measurement, which should always be metric tons. Some alternatives +are not interchangeable because they are in different units, e.g., +abundance, which is in terms of numbers rather than weight.} +\item{Alternatives}{stock biomass, total biomass, abundance (numbers of fish), +biomass wet weight, biomass index} +\item{Range of possible values}{0--Inf} +\item{Units}{} +} +} +\usage{ +Biomass +} +\description{ +Weight of fish within a stock. If referring to a certain portion of the +stock, it should be made clear what portion of the stock the biomass +pertains to. Model output related to biomass is assumed to be measured +at the beginning of the year unless otherwise specified. +} +\keyword{datasets} diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..4aba64d --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,8 @@ +library(testthat) +library(fishdictionary) +library(tools) # For test-validate-Rd.R + +# Use "extdata" in "inst" because its loaded with R packages +validate_Rd_path <- system.file(file.path("extdata", "testthat_data"), package = "fishdictionary") + +test_check("fishdictionary") \ No newline at end of file diff --git a/tests/testthat/test-validate-Rd.R b/tests/testthat/test-validate-Rd.R new file mode 100644 index 0000000..04c8ab7 --- /dev/null +++ b/tests/testthat/test-validate-Rd.R @@ -0,0 +1,37 @@ +test_that("validate_Rd validators work as expected", { + + Rd_file <- file.path(validate_Rd_path, "validate_Rd_no_description.Rd") + expect_error(validate_Rd(Rd_file), + regexp = "Description is not provided. This should be capitalized and not end in a period.") + + Rd_file <- file.path(validate_Rd_path, "validate_Rd_no_examples.Rd") + expect_error(validate_Rd(Rd_file), + regexp = "Examples are not provided. Use NA if there is no input for examples.") + + Rd_file <- file.path(validate_Rd_path, "validate_Rd_no_rationale.Rd") + expect_error(validate_Rd(Rd_file), + regexp = "Rationale is not provided.") + + Rd_file <- file.path(validate_Rd_path, "validate_Rd_no_alternatives.Rd") + expect_error(validate_Rd(Rd_file), + regexp = "Alternatives are not provided. Use NA if there is no input for alternatives.") + + Rd_file <- file.path(validate_Rd_path, "validate_Rd_no_range_of_possible_values.Rd") + expect_error(validate_Rd(Rd_file), + regexp = "Range of possible values is not provided. Use NA if there is no input for range of possible values.") + + Rd_file <- file.path(validate_Rd_path, "validate_Rd_no_units.Rd") + expect_error(validate_Rd(Rd_file), + regexp = "Units are not provided. Use NA if there is no input for units.") + + Rd_file <- file.path(validate_Rd_path, "validate_Rd_no_units.Rd") + expect_error(validate_Rd(Rd_file), + regexp = "Units are not provided. Use NA if there is no input for units.") + + Rd_file <- file.path(validate_Rd_path, "validate_Rd_good_input.Rd") + expect_message(validate_Rd(Rd_file), + regexp = paste("Term Biomass has passed all validations!")) + + Rd_file <- file.path(validate_Rd_path, "validate_Rd_missing_items.Rd") + expect_error(validate_Rd(Rd_file)) +}) \ No newline at end of file From cdde49642e6906e6fce56baa09065570759a2493 Mon Sep 17 00:00:00 2001 From: Bai Li Date: Thu, 6 Oct 2022 14:54:08 -0400 Subject: [PATCH 3/7] GHA: add r cmd check workflow --- .github/workflows/call-r-cmd-check.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/call-r-cmd-check.yml diff --git a/.github/workflows/call-r-cmd-check.yml b/.github/workflows/call-r-cmd-check.yml new file mode 100644 index 0000000..b0469d4 --- /dev/null +++ b/.github/workflows/call-r-cmd-check.yml @@ -0,0 +1,12 @@ +# Run r cmd check +name: call-r-cmd-check +# on specifies the build triggers. See more info at https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows +on: +# The default build trigger is to run the action on every push and pull request, for any branch + push: + # To run the default repository branch weekly on sunday, uncomment the following 2 lines + #schedule: + #- cron: '0 0 * * 0' +jobs: + call-workflow: + uses: nmfs-fish-tools/ghactions4r/.github/workflows/r-cmd-check.yml@main \ No newline at end of file From 5b6b9d742ca8fbdcdc9ac39bfbec8dcd8647c5d0 Mon Sep 17 00:00:00 2001 From: Bai Li Date: Thu, 6 Oct 2022 15:02:24 -0400 Subject: [PATCH 4/7] add testthat --- DESCRIPTION | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index 3fd376e..6c4a77f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,3 +13,7 @@ RoxygenNote: 7.2.1 Imports: mvbutils, tools +Suggests: + testthat (>= 3.0.0) +Config/testthat/edition: 3 +Config/testthat/parallel: true \ No newline at end of file From 314d3b6a191eff277013f3e8b1a3b787451dbccf Mon Sep 17 00:00:00 2001 From: Bai Li Date: Thu, 6 Oct 2022 15:16:42 -0400 Subject: [PATCH 5/7] add an empty line to the end of the file --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6c4a77f..ad9106d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,4 +16,4 @@ Imports: Suggests: testthat (>= 3.0.0) Config/testthat/edition: 3 -Config/testthat/parallel: true \ No newline at end of file +Config/testthat/parallel: true From 5aa77d31a242486cfb985c933af70f9cc1f9fc35 Mon Sep 17 00:00:00 2001 From: Bai Li Date: Thu, 6 Oct 2022 15:17:38 -0400 Subject: [PATCH 6/7] change testthat data path --- tests/testthat.R | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/testthat.R b/tests/testthat.R index 4aba64d..8261ee3 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -2,7 +2,4 @@ library(testthat) library(fishdictionary) library(tools) # For test-validate-Rd.R -# Use "extdata" in "inst" because its loaded with R packages -validate_Rd_path <- system.file(file.path("extdata", "testthat_data"), package = "fishdictionary") - test_check("fishdictionary") \ No newline at end of file From 63f42ff012adfecbc745133c26ed0b8245af61ee Mon Sep 17 00:00:00 2001 From: Bai Li Date: Thu, 6 Oct 2022 15:28:43 -0400 Subject: [PATCH 7/7] test: update testthat data path --- tests/testthat/test-validate-Rd.R | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-validate-Rd.R b/tests/testthat/test-validate-Rd.R index 04c8ab7..57fce13 100644 --- a/tests/testthat/test-validate-Rd.R +++ b/tests/testthat/test-validate-Rd.R @@ -1,5 +1,13 @@ test_that("validate_Rd validators work as expected", { + pkg_path <- find.package("fishdictionary") + + if (!file.exists(file.path(pkg_path, "inst"))) { + validate_Rd_path <- file.path(pkg_path, "extdata", "testthat_data") + } else { + validate_Rd_path <- file.path(pkg_path, "inst", "extdata", "testthat_data") + } + Rd_file <- file.path(validate_Rd_path, "validate_Rd_no_description.Rd") expect_error(validate_Rd(Rd_file), regexp = "Description is not provided. This should be capitalized and not end in a period.") @@ -24,10 +32,6 @@ test_that("validate_Rd validators work as expected", { expect_error(validate_Rd(Rd_file), regexp = "Units are not provided. Use NA if there is no input for units.") - Rd_file <- file.path(validate_Rd_path, "validate_Rd_no_units.Rd") - expect_error(validate_Rd(Rd_file), - regexp = "Units are not provided. Use NA if there is no input for units.") - Rd_file <- file.path(validate_Rd_path, "validate_Rd_good_input.Rd") expect_message(validate_Rd(Rd_file), regexp = paste("Term Biomass has passed all validations!"))