phuse-org / valtools

Validation framework for R packages used in clinical research and drug development.
https://phuse-org.github.io/valtools/
Other
51 stars 10 forks source link

vt_scrape_function_editors does not play nicely w/ @include roxy block #142

Open mariev opened 3 years ago

mariev commented 3 years ago

When evaluating function author table for {scharpbama}, running into issue with file conditions_base.R due to the first line structure

conditions_base.R:

#' @include reexport-scharputils.R
NULL

evaluates to:

> vt_scrape_function_editors(tags = c("editor", "editDate"))

Error: NULL/deprecated functions must have a title.
Review file `C:/Users/mvendett/Documents/Github/scharpbama/R/conditions_base.R`, line 2
mariev commented 3 years ago

the error message was very helpful! 👍 👍 👍

mariev commented 3 years ago

digging into this a bit further, it looks like orphan #' @include + NULL are expected to have a #' @title line i.e.

  withr::with_tempdir({

    ## test setup
    captured_output <- capture.output({vt_create_package(open = FALSE)})
    usethis::proj_set(force = TRUE)
    usethis::use_r("hello_world.R", open = FALSE)

    writeLines(c(
      "#' @title placeholder",
      "#' @name placeholder",
      "#' @include some-other-file.R",
      "NULL",
      "",
      "#' A function to greet someone",
      "#' @param name someone's name",
      "#' @editor An author",
      "#' @editDate 2021-01-01",
      "#' @return text greeting",
      "#' @export",
      " hello_world <- function(name){",
      "   paste(\"Hello \", name)",
      "}"
    ), file.path(usethis::proj_get(), "R", "hello_world.R"))
    testthat::expect_equal(vt_scrape_function_editors(tags = c("editor", "editDate")),
                 data.frame(functions = c("hello_world"),
                            editor = c("An author"),
                            editDate = c("2021-01-01"),
                            stringsAsFactors = FALSE))
  })

  withr::with_tempdir({

    ## test setup
    captured_output <- capture.output({vt_create_package(open = FALSE)})
    usethis::proj_set(force = TRUE)
    usethis::use_r("hello_world.R", open = FALSE)

    writeLines(c(
      "#' @include some-other-file.R",
      "NULL",
      "",
      "#' A function to greet someone",
      "#' @param name someone's name",
      "#' @editor An author",
      "#' @editDate 2021-01-01",
      "#' @return text greeting",
      "#' @export",
      " hello_world <- function(name){",
      "   paste(\"Hello \", name)",
      "}"
    ), file.path(usethis::proj_get(), "R", "hello_world.R"))

    testthat::expect_error(
      vt_scrape_function_editors(tags = c("editor", "editDate"))
      )
  })

while I can certainly add the extra tags when coming across this internally, my understanding is that the firstscenario is not the norm when reordering the collate field via roxygen2 (note that only @title is needed for vt_scrape_function_editors, but @name is needed to avoid devtools::check warning when @title is used.... 🙄 )

@thebioengineer what do you think use case should be?