Creates or updates package files based on the information in a beekeeper
config file (generated by use_beekeeper() or manually). The files enforce
an opinionated framework for API packages.
Usage
generate_pkg(
api_abbr = read_api_abbr(pkg_dir, config_filename),
api_definition = read_api_definition(pkg_dir, read_rapid_filename(pkg_dir,
config_filename)),
api_title = read_api_title(pkg_dir, config_filename),
use_prefix = FALSE,
exclude_from_response = character(),
config_filename = "_beekeeper.yml",
pkg_dir = "."
)Arguments
- api_abbr
(
character(1)) A short (about 2-5 letter) abbreviation for the API, for use in function names and environment variables.- api_definition
(
rapid::class_rapid) The API definition to generate package code from.- api_title
(
character(1)) The API title used in generated package files.- use_prefix
(
logical(1)) Whether to includeapi_abbras a prefix in generated path function names. WhenFALSE(the default), functions are named{operation_id}andreq_{operation_id}. WhenTRUE, functions are named{api_abbr}_{operation_id}andreq_{api_abbr}_{operation_id}.- exclude_from_response
(
character) Field names to remove from response specs before generating parsers. Fields matching these names will be dropped from the response spec. If only one field remains after exclusion and it is of type"df","row", or"recursive", the spec is simplified so that the response parser targets that field directly.- config_filename
(
character(1)orfs_path) The path to a beekeeper yaml config file (relative to the package root).- pkg_dir
(
character(1)orfs_path) The directory containing package files.
See also
Other package generation functions:
generate_pkg_auth(),
generate_pkg_paths(),
generate_pkg_req_prepare(),
generate_pkg_shared_params()
Examples
# Set up an empty package.
pkg_dir <- unclass(fs::path_norm(withr::local_tempdir()))
usethis::create_package(pkg_dir, open = FALSE, check_name = FALSE)
#> ✔ Creating /tmp/RtmprMicgs/file52e44ac4984/.
#> ✔ Setting active project to "/tmp/RtmprMicgs/file52e44ac4984".
#> ✔ Creating R/.
#> ✔ Writing DESCRIPTION.
#> Package: file52e44ac4984
#> Title: What the Package Does (One Line, Title Case)
#> Version: 0.0.0.9000
#> Authors@R (parsed):
#> * First Last <first.last@example.com> [aut, cre]
#> Description: What the package does (one paragraph).
#> License: `use_mit_license()`, `use_gpl3_license()` or friends to
#> pick a license
#> Encoding: UTF-8
#> Roxygen: list(markdown = TRUE)
#> RoxygenNote: 8.0.0
#> ✔ Writing NAMESPACE.
#> ✔ Setting active project to "<no active project>".
bk_files <- c("_beekeeper.yml", "_beekeeper_rapid.rds")
fs::file_copy(
fs::path_package("beekeeper", "guru", bk_files),
fs::path(pkg_dir, bk_files)
)
usethis::local_project(pkg_dir)
#> ✔ Setting active project to "/tmp/RtmprMicgs/file52e44ac4984".
#> ✔ Setting active project to "<no active project>".
# Generate a package.
generate_pkg()
#> Warning: cannot open file '/__w/beekeeper/beekeeper/docs/dev/reference/_beekeeper.yml': No such file or directory
#> Error in file(file, "rt", encoding = fileEncoding): cannot open the connection
fs::dir_ls("R")
#> Error: [ENOENT] Failed to search directory 'R': no such file or directory
fs::dir_ls("tests/testthat")
#> Error: [ENOENT] Failed to search directory 'tests/testthat': no such file or directory
# Clean up.
withr::deferred_run()
#> No deferred expressions to run