From e64fd04cf5f7737b14cb74b9342711eef6e60a81 Mon Sep 17 00:00:00 2001 From: Colin Fay Date: Wed, 12 Oct 2022 21:23:55 +0200 Subject: [PATCH 01/55] chore: merging changes from CRAN upload (#928) --- DESCRIPTION | 5 +-- R/add_dockerfiles.R | 10 +++--- R/add_r_files.R | 4 --- R/test_helpers.R | 5 --- R/with_opt.R | 42 ++++++++++++------------ man/dockerfiles.Rd | 10 +++--- man/get_golem_options.Rd | 42 ++++++++++++------------ man/testhelpers.Rd | 4 --- tests/testthat/test-add_deploy_helpers.R | 5 ++- tests/testthat/test-extra_sysreqs.R | 3 ++ tests/testthat/test-renv_stuff.R | 3 +- 11 files changed, 64 insertions(+), 69 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index db46dc66..f8ec31f7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: golem Title: A Framework for Robust Shiny Applications -Version: 0.3.3.9007 +Version: 0.3.4 Authors@R: c(person(given = "Colin", family = "Fay", @@ -82,7 +82,8 @@ Suggests: testthat, tools, withr, - attachment (>= 0.2.5) + attachment (>= 0.2.5), + renv VignetteBuilder: knitr Config/testthat/edition: 3 diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index 563d6059..c3ae80aa 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -62,12 +62,12 @@ talk_once <- function(.f, msg = "") { #' @examples #' \donttest{ #' # Add a standard Dockerfile -#' if (interactive()) { +#' if (interactive() & requireNamespace("dockerfiler")) { #' add_dockerfile() #' } #' # Crete a 'deploy' folder containing everything needed to deploy #' # the golem using docker based on {renv} -#' if (interactive()) { +#' if (interactive() & requireNamespace("dockerfiler")) { #' add_dockerfile_with_renv( #' # lockfile = "renv.lock", # uncomment to use existing renv.lock file #' output_dir = "deploy" @@ -82,13 +82,13 @@ talk_once <- function(.f, msg = "") { #' ) #' } #' # Add a Dockerfile for ShinyProxy -#' if (interactive()) { +#' if (interactive() & requireNamespace("dockerfiler")) { #' add_dockerfile_shinyproxy() #' } #' #' # Crete a 'deploy' folder containing everything needed to deploy #' # the golem with ShinyProxy using docker based on {renv} -#' if (interactive()) { +#' if (interactive() & requireNamespace("dockerfiler")) { #' add_dockerfile_with_renv( #' # lockfile = "renv.lock",# uncomment to use existing renv.lock file #' output_dir = "deploy" @@ -106,7 +106,7 @@ talk_once <- function(.f, msg = "") { #' } #' #' # Add a Dockerfile for Heroku -#' if (interactive()) { +#' if (interactive() & requireNamespace("dockerfiler")) { #' add_dockerfile_heroku() #' } #' } diff --git a/R/add_r_files.R b/R/add_r_files.R index 7624ba10..1e6e66fa 100644 --- a/R/add_r_files.R +++ b/R/add_r_files.R @@ -68,10 +68,6 @@ add_r_files <- function( } if (with_test) { - rlang::check_installed( - "usethis", - "to build the test structure." - ) usethis::use_test( basename( file_path_sans_ext( diff --git a/R/test_helpers.R b/R/test_helpers.R index 5236ecec..14baa080 100644 --- a/R/test_helpers.R +++ b/R/test_helpers.R @@ -8,9 +8,6 @@ #' @return A testthat result. #' @export #' @rdname testhelpers -#' -#' @examples -#' expect_shinytag(shiny::tags$span("1")) expect_shinytag <- function(object) { rlang::check_installed( "testthat", @@ -27,8 +24,6 @@ expect_shinytag <- function(object) { #' @export #' @rdname testhelpers -#' @examples -#' expect_shinytaglist(shiny::tagList(1)) expect_shinytaglist <- function(object) { rlang::check_installed( "testthat", diff --git a/R/with_opt.R b/R/with_opt.R index dfde7a5d..14af6d68 100644 --- a/R/with_opt.R +++ b/R/with_opt.R @@ -64,38 +64,38 @@ with_golem_options <- function( #' @return The value of the option. #' #' @examples -#' \dontrun{ #' #' # Define and use golem_options +#' if (interactive()) { +#' # 1. Pass parameters to `run_app` #' -#' # 1. Pass parameters to `run_app` +#' # to set default value, edit run_app like this : #' -#' # to set default value, edit run_app like this : -#' run_app <- function( +#' run_app <- function( #' title = "this", #' content = "that" -#' ) { -#' with_golem_options( -#' app = shinyApp( -#' ui = app_ui, -#' server = app_server -#' ), -#' golem_opts = list( -#' p1 = p1, -#' p3 = p3 +#' ) { +#' with_golem_options( +#' app = shinyApp( +#' ui = app_ui, +#' server = app_server +#' ), +#' golem_opts = list( +#' p1 = p1, +#' p3 = p3 +#' ) #' ) -#' ) -#' } +#' } #' -#' # 2. Get the values from the UI side +#' # 2. Get the values from the UI side #' -#' h1(get_golem_options("title")) +#' h1(get_golem_options("title")) #' -#' # 3. Get the value from the server-side +#' # 3. Get the value from the server-side #' -#' output$param <- renderPrint({ -#' paste("param p2 = ", get_golem_options("p2")) -#' }) +#' output$param <- renderPrint({ +#' paste("param p2 = ", get_golem_options("p2")) +#' }) #' } #' get_golem_options <- function(which = NULL) { diff --git a/man/dockerfiles.Rd b/man/dockerfiles.Rd index dfd5715b..35fdab0c 100644 --- a/man/dockerfiles.Rd +++ b/man/dockerfiles.Rd @@ -167,12 +167,12 @@ a generic Dockerfile, while \code{add_dockerfile_shinyproxy()}, \code{add_docker \examples{ \donttest{ # Add a standard Dockerfile -if (interactive()) { +if (interactive() & requireNamespace("dockerfiler")) { add_dockerfile() } # Crete a 'deploy' folder containing everything needed to deploy # the golem using docker based on {renv} -if (interactive()) { +if (interactive() & requireNamespace("dockerfiler")) { add_dockerfile_with_renv( # lockfile = "renv.lock", # uncomment to use existing renv.lock file output_dir = "deploy" @@ -187,13 +187,13 @@ if (interactive()) { ) } # Add a Dockerfile for ShinyProxy -if (interactive()) { +if (interactive() & requireNamespace("dockerfiler")) { add_dockerfile_shinyproxy() } # Crete a 'deploy' folder containing everything needed to deploy # the golem with ShinyProxy using docker based on {renv} -if (interactive()) { +if (interactive() & requireNamespace("dockerfiler")) { add_dockerfile_with_renv( # lockfile = "renv.lock",# uncomment to use existing renv.lock file output_dir = "deploy" @@ -211,7 +211,7 @@ if (interactive()) { } # Add a Dockerfile for Heroku -if (interactive()) { +if (interactive() & requireNamespace("dockerfiler")) { add_dockerfile_heroku() } } diff --git a/man/get_golem_options.Rd b/man/get_golem_options.Rd index b768d479..a0e2895f 100644 --- a/man/get_golem_options.Rd +++ b/man/get_golem_options.Rd @@ -18,38 +18,38 @@ server and UI from your app, in order to call the parameters passed to \code{run_app()}. } \examples{ -\dontrun{ # Define and use golem_options +if (interactive()) { + # 1. Pass parameters to `run_app` -# 1. Pass parameters to `run_app` + # to set default value, edit run_app like this : -# to set default value, edit run_app like this : -run_app <- function( + run_app <- function( title = "this", content = "that" -) { - with_golem_options( - app = shinyApp( - ui = app_ui, - server = app_server - ), - golem_opts = list( - p1 = p1, - p3 = p3 + ) { + with_golem_options( + app = shinyApp( + ui = app_ui, + server = app_server + ), + golem_opts = list( + p1 = p1, + p3 = p3 + ) ) - ) -} + } -# 2. Get the values from the UI side + # 2. Get the values from the UI side -h1(get_golem_options("title")) + h1(get_golem_options("title")) -# 3. Get the value from the server-side + # 3. Get the value from the server-side -output$param <- renderPrint({ - paste("param p2 = ", get_golem_options("p2")) -}) + output$param <- renderPrint({ + paste("param p2 = ", get_golem_options("p2")) + }) } } diff --git a/man/testhelpers.Rd b/man/testhelpers.Rd index 6ad0ed56..0b516339 100644 --- a/man/testhelpers.Rd +++ b/man/testhelpers.Rd @@ -35,7 +35,3 @@ A testthat result. These functions are designed to be used inside the tests in your Shiny app package. } -\examples{ -expect_shinytag(shiny::tags$span("1")) -expect_shinytaglist(shiny::tagList(1)) -} diff --git a/tests/testthat/test-add_deploy_helpers.R b/tests/testthat/test-add_deploy_helpers.R index 7057e65a..b798603f 100644 --- a/tests/testthat/test-add_deploy_helpers.R +++ b/tests/testthat/test-add_deploy_helpers.R @@ -1,5 +1,8 @@ test_that("add_dockerfiles", { - skip_if_not_installed("dockerfiler", "0.1.4") + skip_if_not_installed("renv") + skip_if_not_installed("dockerfiler", "0.2.0") + skip_if_not_installed("attachment", "0.2.5") + with_dir(pkg, { for (fun in list( add_dockerfile, diff --git a/tests/testthat/test-extra_sysreqs.R b/tests/testthat/test-extra_sysreqs.R index 2b5f34d8..6530b095 100644 --- a/tests/testthat/test-extra_sysreqs.R +++ b/tests/testthat/test-extra_sysreqs.R @@ -1,4 +1,7 @@ test_that("test extra sysreqs", { + skip_if_not_installed("renv") + skip_if_not_installed("dockerfiler", "0.2.0") + skip_if_not_installed("attachment", "0.2.5") with_dir(pkg, { for (fun in list( add_dockerfile, diff --git a/tests/testthat/test-renv_stuff.R b/tests/testthat/test-renv_stuff.R index 43d74c15..f63449e4 100644 --- a/tests/testthat/test-renv_stuff.R +++ b/tests/testthat/test-renv_stuff.R @@ -1,6 +1,7 @@ test_that("add_dockerfiles_renv and add_dockerfile_with_renv_shinyproxy all output file are present", { + skip_if_not_installed("renv") skip_if_not_installed("dockerfiler", "0.2.0") - + skip_if_not_installed("attachment", "0.2.5") with_dir(pkg, { for (fun in list( add_dockerfile_with_renv, From 07e31b7042c0575b4e8545d7915ce5c4c178573e Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 12 Oct 2022 21:27:59 +0200 Subject: [PATCH 02/55] chore: version bump We needed to release a version for golem to stay on CRAN but a real release was not ready, hence a small 0.3.4 --- DESCRIPTION | 2 +- NEWS.md | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index db46dc66..58c2ca47 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: golem Title: A Framework for Robust Shiny Applications -Version: 0.3.3.9007 +Version: 0.3.3.9008 Authors@R: c(person(given = "Colin", family = "Fay", diff --git a/NEWS.md b/NEWS.md index feb3d628..425660a8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ > Notes: the # between parenthesis referes to the related issue on GitHub, and the @ refers to an external contributor solving this issue. -# golem 0.3.3.9000+ +# golem 0.3.4.9000+ ## Soft deprecated @@ -37,6 +37,10 @@ ## Internal changes +# golem 0.3.4. + +This version has a small internal change in the tests, so that it can stay on CRAN. + # golem 0.3.3 ## New functions From e6f3fad0251ba02c4f0b7f20e2240cf0c14369d9 Mon Sep 17 00:00:00 2001 From: Colin Fay Date: Wed, 12 Oct 2022 22:11:39 +0200 Subject: [PATCH 03/55] feat: removed {usethis} hard dep (#929) --- DESCRIPTION | 8 +-- NAMESPACE | 7 --- NEWS.md | 2 +- R/add_dockerfiles.R | 22 ++------ R/add_dockerfiles_renv.R | 2 +- R/add_r_files.R | 2 +- R/add_rstudio_files.R | 9 +-- R/create_golem.R | 17 ++++-- R/modules_fn.R | 2 +- R/set_golem_options.R | 3 +- R/use_recommended.R | 15 +---- R/use_utils.R | 5 +- R/usethis_bootstrap.R | 116 +++++++++++++++++++++++++++++++++++++++ 13 files changed, 151 insertions(+), 59 deletions(-) create mode 100644 R/usethis_bootstrap.R diff --git a/DESCRIPTION b/DESCRIPTION index a507f601..e44fbbda 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: golem Title: A Framework for Robust Shiny Applications -Version: 0.3.4.9000 +Version: 0.3.4.9001 Authors@R: c(person(given = "Colin", family = "Fay", @@ -55,12 +55,10 @@ Imports: crayon, desc, here, - fs, htmltools, rlang (>= 1.0.0), rstudioapi, shiny (>= 1.5.0), - usethis (>= 1.6.0), utils, yaml Suggests: @@ -83,7 +81,9 @@ Suggests: tools, withr, attachment (>= 0.2.5), - renv + renv, + usethis (>= 1.6.0), + fs VignetteBuilder: knitr Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 1f59daf5..7cdfebe7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -111,13 +111,6 @@ importFrom(shiny,addResourcePath) importFrom(shiny,getShinyOption) importFrom(shiny,includeScript) importFrom(shiny,tags) -importFrom(usethis,create_project) -importFrom(usethis,proj_set) -importFrom(usethis,use_build_ignore) -importFrom(usethis,use_latest_dependencies) -importFrom(usethis,use_package) -importFrom(usethis,use_spell_check) -importFrom(usethis,use_testthat) importFrom(utils,capture.output) importFrom(utils,file.edit) importFrom(utils,getFromNamespace) diff --git a/NEWS.md b/NEWS.md index 425660a8..d39b15dc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,7 +15,7 @@ ## New features / user visible changes -+ The following hard dependencies have been moved to soft dependencies, as you'll only need them while developing: `{pkgload}`, `{roxygen2}`, `{fs}` ++ The following hard dependencies have been moved to soft dependencies, as you'll only need them while developing: `{pkgload}`, `{roxygen2}`, `{fs}`, `{usethis}` + Soft dependency check is now done via `rlang::check_installed()` (#835) diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index c3ae80aa..f7821b49 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -9,17 +9,6 @@ talk_once <- function(.f, msg = "") { } } -talk_once <- function(.f, msg = "") { - talk <- TRUE - function(...) { - if (talk) { - talk <<- FALSE - cat_red_bullet(msg) - } - .f(...) - } -} - #' Create a Dockerfile for your App #' #' Build a container containing your Shiny App. `add_dockerfile()` and `add_dockerfile_with_renv()` and `add_dockerfile_with_renv()` creates @@ -55,7 +44,6 @@ talk_once <- function(.f, msg = "") { #' @export #' @rdname dockerfiles #' -#' @importFrom usethis use_build_ignore #' @importFrom desc desc_get_deps #' @importFrom rstudioapi navigateToFile isAvailable hasFun #' @@ -180,7 +168,9 @@ add_dockerfile_ <- talk_once( where <- fs_path(pkg, output) - usethis::use_build_ignore(basename(where)) + usethis_use_build_ignore( + basename(where) + ) dock <- dockerfiler::dock_from_desc( path = path, @@ -289,7 +279,7 @@ add_dockerfile_shinyproxy_ <- talk_once( ) where <- fs_path(pkg, output) - usethis::use_build_ignore(output) + usethis_use_build_ignore(output) dock <- dockerfiler::dock_from_desc( path = path, @@ -392,7 +382,7 @@ add_dockerfile_heroku_ <- talk_once( ) where <- fs_path(pkg, output) - usethis::use_build_ignore(output) + usethis_use_build_ignore(output) dock <- dockerfiler::dock_from_desc( path = path, @@ -455,7 +445,7 @@ add_dockerfile_heroku_ <- talk_once( try(file.edit(output)) } } - usethis::use_build_ignore(files = output) + usethis_use_build_ignore(files = output) return(invisible(dock)) }, " diff --git a/R/add_dockerfiles_renv.R b/R/add_dockerfiles_renv.R index b9c59503..93f5d3fb 100644 --- a/R/add_dockerfiles_renv.R +++ b/R/add_dockerfiles_renv.R @@ -37,7 +37,7 @@ add_dockerfile_with_renv_ <- function( # add output_dir in Rbuildignore if the output is inside the golem if (normalizePath(dirname(output_dir)) == normalizePath(source_folder)) { - usethis::use_build_ignore(output_dir) + usethis_use_build_ignore(output_dir) } if (is.null(lockfile)) { diff --git a/R/add_r_files.R b/R/add_r_files.R index 1e6e66fa..a4bcb24f 100644 --- a/R/add_r_files.R +++ b/R/add_r_files.R @@ -68,7 +68,7 @@ add_r_files <- function( } if (with_test) { - usethis::use_test( + usethis_use_test( basename( file_path_sans_ext( where diff --git a/R/add_rstudio_files.R b/R/add_rstudio_files.R index f756e1e1..44955959 100644 --- a/R/add_rstudio_files.R +++ b/R/add_rstudio_files.R @@ -1,6 +1,5 @@ #' @importFrom utils capture.output #' @importFrom cli cat_bullet -#' @importFrom usethis use_build_ignore use_package add_rstudio_files <- function( pkg, open, @@ -18,8 +17,6 @@ add_rstudio_files <- function( reason = "to deploy on RStudio products." ) - rlang::check_installed("usethis") - disable_autoload( pkg = pkg ) @@ -31,8 +28,8 @@ add_rstudio_files <- function( write(..., here, append = TRUE) } - use_build_ignore(basename(where)) - use_build_ignore("rsconnect") + usethis_use_build_ignore(basename(where)) + usethis_use_build_ignore("rsconnect") write_there("# Launch the ShinyApp (Do not remove this comment)") write_there("# To deploy, run: rsconnect::deployApp()") write_there("# Or use the blue button on top of this file") @@ -47,7 +44,7 @@ add_rstudio_files <- function( ) # We add {pkgload} as a dep because it's required to deploy on Connect & stuff - usethis::use_package("pkgload") + usethis_use_package("pkgload") cat_created(where) cat_line("To deploy, run:") diff --git a/R/create_golem.R b/R/create_golem.R index 5f4b5651..12bc8db6 100644 --- a/R/create_golem.R +++ b/R/create_golem.R @@ -57,7 +57,6 @@ replace_package_name <- function( #' @importFrom cli cat_rule cat_line #' @importFrom utils getFromNamespace #' @importFrom rstudioapi isAvailable openProject hasFun -#' @importFrom usethis use_latest_dependencies create_project #' @importFrom yaml write_yaml #' #' @export @@ -81,7 +80,15 @@ create_golem <- function( if (check_name) { cat_rule("Checking package name") - getFromNamespace("check_package_name", "usethis")(package_name) + rlang::check_installed( + "usethis", + version = "1.6.0", + reason = "to check the package name." + ) + getFromNamespace( + "check_package_name", + "usethis" + )(package_name) cat_green_tick("Valid package name") } @@ -102,9 +109,9 @@ create_golem <- function( } } else { cat_rule("Creating dir") - usethis::create_project( + usethis_create_project( path = path_to_golem, - open = FALSE, + open = FALSE ) here::set_here(path_to_golem) cat_green_tick("Created package directory") @@ -188,7 +195,7 @@ create_golem <- function( old <- setwd(path_to_golem) - use_latest_dependencies() + usethis_use_latest_dependencies() # No .Rprofile for now # cat_rule("Appending .Rprofile") diff --git a/R/modules_fn.R b/R/modules_fn.R index c55d0cac..557e1089 100644 --- a/R/modules_fn.R +++ b/R/modules_fn.R @@ -275,7 +275,7 @@ use_module_test <- function( if (!fs_dir_exists( fs_path(pkg, "tests", "testthat") )) { - usethis::use_testthat() + usethis_use_testthat() } path <- fs_path( diff --git a/R/set_golem_options.R b/R/set_golem_options.R index bf9d59e8..28ddd90c 100644 --- a/R/set_golem_options.R +++ b/R/set_golem_options.R @@ -32,7 +32,6 @@ #' #' @export #' @importFrom attempt stop_if_not -#' @importFrom usethis proj_set #' #' @return Used for side-effects for the setters, and values from the #' config in the getters. @@ -96,5 +95,5 @@ set_golem_options <- function( ) } - proj_set(golem_wd) + usethis_proj_set(golem_wd) } diff --git a/R/use_recommended.R b/R/use_recommended.R index c72d85a7..1a348a9c 100644 --- a/R/use_recommended.R +++ b/R/use_recommended.R @@ -10,7 +10,6 @@ #' @param recommended A vector of recommended packages. #' @param spellcheck Whether or not to use a spellcheck test. #' -#' @importFrom usethis use_testthat use_package #' @rdname use_recommended #' #' @export @@ -29,7 +28,7 @@ use_recommended_deps <- function( on.exit(setwd(old)) for (i in sort(recommended)) { - try(use_package(i)) + try(usethis_use_package(i)) } cat_green_tick("Dependencies added") @@ -38,7 +37,6 @@ use_recommended_deps <- function( #' @rdname use_recommended #' @export -#' @importFrom usethis use_testthat use_package use_spell_check #' @importFrom utils capture.output #' @importFrom attempt without_warning stop_if use_recommended_tests <- function( @@ -50,17 +48,12 @@ use_recommended_tests <- function( ) { old <- setwd(fs_path_abs(pkg)) - rlang::check_installed( - "fs", - reason = "for file & directory manipulation." - ) - on.exit(setwd(old)) if (!fs_dir_exists( fs_path(fs_path_abs(pkg), "tests") )) { - without_warning(use_testthat)() + without_warning(usethis_use_testthat)() } if (!requireNamespace("processx")) { stop("Please install the {processx} package to add the recommended tests.") @@ -79,13 +72,11 @@ use_recommended_tests <- function( ) if (spellcheck) { - use_spell_check( + usethis_use_spell_check( vignettes = vignettes, lang = lang, error = error ) } - - cat_green_tick("Tests added") } diff --git a/R/use_utils.R b/R/use_utils.R index e9de1af3..ef2c1f46 100644 --- a/R/use_utils.R +++ b/R/use_utils.R @@ -12,7 +12,6 @@ #' #' @importFrom cli cat_bullet #' @importFrom utils capture.output -#' @importFrom usethis use_testthat #' #' @return Used for side-effects. use_utils_ui <- function( @@ -30,7 +29,7 @@ use_utils_ui <- function( if (with_test) { if (!isTRUE(fs_dir_exists("tests"))) { - use_testthat() + usethis_use_testthat() } pth <- fs_path( pkg, @@ -82,7 +81,7 @@ use_utils_server <- function( if (with_test) { if (!isTRUE(fs_dir_exists("tests"))) { - use_testthat() + usethis_use_testthat() } pth <- fs_path( pkg, diff --git a/R/usethis_bootstrap.R b/R/usethis_bootstrap.R new file mode 100644 index 00000000..1e513da5 --- /dev/null +++ b/R/usethis_bootstrap.R @@ -0,0 +1,116 @@ + +# All the fns here check that {usethis} is installed +# before doing anything. +check_usethis_installed <- function(reason = "for project and file manipulation.") { + rlang::check_installed( + "usethis", + version = "1.6.0", + reason = reason + ) +} + +usethis_use_build_ignore <- function( + files, + escape = TRUE +) { + check_usethis_installed( + reason = "to ignore files in the build." + ) + usethis::use_build_ignore( + files, + escape + ) +} +usethis_use_package <- function( + package, + type = "Imports", + min_version = NULL +) { + check_usethis_installed( + reason = "to add dependencies to DESCRIPTION." + ) + usethis::use_package( + package, + type, + min_version + ) +} + +usethis_create_project <- function( + path, + rstudio = rstudioapi::isAvailable(), + open = rlang::is_interactive() +) { + check_usethis_installed( + reason = "to create a project." + ) + usethis::create_project( + path, + rstudio, + open + ) +} +usethis_use_latest_dependencies <- function( + overwrite = FALSE, + source = c("local", "CRAN") +) { + check_usethis_installed( + reason = "to set dependency version." + ) + usethis::use_latest_dependencies( + overwrite, + source + ) +} + +usethis_proj_set <- function( + path = ".", + force = FALSE +) { + check_usethis_installed( + reason = "to set project." + ) + usethis::proj_set( + path, + force + ) +} +usethis_use_testthat <- function( + edition = NULL, + parallel = FALSE +) { + check_usethis_installed( + reason = "to add {testthat} infrastructure." + ) + usethis::use_testthat( + edition, + parallel + ) +} +usethis_use_test <- function( + name = NULL, + open = rlang::is_interactive() +) { + check_usethis_installed( + reason = "to add tests." + ) + usethis::use_test( + name, + open + ) +} + +usethis_use_spell_check <- function( + vignettes = TRUE, + lang = "en-US", + error = FALSE +) { + check_usethis_installed( + reason = "to add spellcheck." + ) + usethis::use_spell_check( + vignettes, + lang, + error + ) +} From 9a809bb29a75466ac8466db86754524eba911281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rochette?= Date: Thu, 13 Oct 2022 08:43:11 +0200 Subject: [PATCH 04/55] fix: unit test requires dependencies in suggests (#919) --- tests/testthat/test-extra_sysreqs.R | 2 ++ tests/testthat/test-pkg_tools.R | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-extra_sysreqs.R b/tests/testthat/test-extra_sysreqs.R index 6530b095..d0e47254 100644 --- a/tests/testthat/test-extra_sysreqs.R +++ b/tests/testthat/test-extra_sysreqs.R @@ -1,3 +1,5 @@ +skip_if_not_installed("dockerfiler", minimum_version = "0.2.0") + test_that("test extra sysreqs", { skip_if_not_installed("renv") skip_if_not_installed("dockerfiler", "0.2.0") diff --git a/tests/testthat/test-pkg_tools.R b/tests/testthat/test-pkg_tools.R index d56c0a43..bc1af90a 100644 --- a/tests/testthat/test-pkg_tools.R +++ b/tests/testthat/test-pkg_tools.R @@ -1,9 +1,11 @@ +skip_if_not_installed("pkgload") + test_that("pkgtools works", { withr::with_dir(pkg, { - expect_equal(pkg_name(), fakename) - expect_equal(pkg_version(), "0.0.0.9000") + expect_equal(pkgload::pkg_name(), fakename) + expect_equal(as.character(pkgload::pkg_version()), "0.0.0.9000") # F-word windows path skip_on_os("windows") - expect_equal(pkg_path(), pkg) + expect_equal(pkgload::pkg_path(), pkg) }) }) From 4f77e1b8659eb52580a17bb31fe789594e4063b6 Mon Sep 17 00:00:00 2001 From: Colin Fay Date: Fri, 14 Oct 2022 08:46:29 +0200 Subject: [PATCH 05/55] refactor: check_installed in their own files (#931) --- R/add_dockerfiles.R | 23 ++------ R/add_dockerfiles_renv.R | 21 +++---- R/boostrap_fs.R | 82 +++++++++++++++++++++++++++ R/bootstrap_attachment.R | 23 ++++++++ R/bootstrap_dockerfiler.R | 68 ++++++++++++++++++++++ R/bootstrap_pkgload.R | 37 ++++++++++++ R/bootstrap_roxygen2.R | 23 ++++++++ R/bootstrap_usethis.R | 116 ++++++++++++++++++++++++++++++++++++++ R/fs_boostrap.R | 82 --------------------------- R/modules_fn.R | 10 +--- R/reload.R | 5 +- R/use_utils.R | 4 -- R/usethis_bootstrap.R | 116 -------------------------------------- 13 files changed, 365 insertions(+), 245 deletions(-) create mode 100644 R/boostrap_fs.R create mode 100644 R/bootstrap_attachment.R create mode 100644 R/bootstrap_dockerfiler.R create mode 100644 R/bootstrap_pkgload.R create mode 100644 R/bootstrap_roxygen2.R create mode 100644 R/bootstrap_usethis.R delete mode 100644 R/fs_boostrap.R delete mode 100644 R/usethis_bootstrap.R diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index f7821b49..168c1dc3 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -160,11 +160,6 @@ add_dockerfile_ <- talk_once( build_golem_from_source = TRUE, extra_sysreqs = NULL ) { - rlang::check_installed( - "dockerfiler", - version = "0.2.0", - reason = "to build a Dockerfile." - ) where <- fs_path(pkg, output) @@ -172,7 +167,7 @@ add_dockerfile_ <- talk_once( basename(where) ) - dock <- dockerfiler::dock_from_desc( + dock <- dockerfiler_dock_from_desc( path = path, FROM = from, AS = as, @@ -272,16 +267,12 @@ add_dockerfile_shinyproxy_ <- talk_once( build_golem_from_source = TRUE, extra_sysreqs = NULL ) { - rlang::check_installed( - "dockerfiler", - version = "0.2.0", - reason = "to build a Dockerfile." - ) + where <- fs_path(pkg, output) usethis_use_build_ignore(output) - dock <- dockerfiler::dock_from_desc( + dock <- dockerfiler_dock_from_desc( path = path, FROM = from, AS = as, @@ -375,16 +366,12 @@ add_dockerfile_heroku_ <- talk_once( build_golem_from_source = TRUE, extra_sysreqs = NULL ) { - rlang::check_installed( - "dockerfiler", - version = "0.2.0", - reason = "to build a Dockerfile." - ) + where <- fs_path(pkg, output) usethis_use_build_ignore(output) - dock <- dockerfiler::dock_from_desc( + dock <- dockerfiler_dock_from_desc( path = path, FROM = from, AS = as, diff --git a/R/add_dockerfiles_renv.R b/R/add_dockerfiles_renv.R index 93f5d3fb..160a357b 100644 --- a/R/add_dockerfiles_renv.R +++ b/R/add_dockerfiles_renv.R @@ -16,17 +16,7 @@ add_dockerfile_with_renv_ <- function( "renv", reason = "to build a Dockerfile." ) - rlang::check_installed( - "dockerfiler", - version = "0.2.0", - reason = "to build a Dockerfile." - ) - rlang::check_installed( - "attachment", - version = "0.2.5", - reason = "to build a Dockerfile." - ) - + # Small hack to prevent warning from rlang::lang() in tests # This should be managed in {attempt} later on x <- suppressWarnings({ @@ -41,7 +31,7 @@ add_dockerfile_with_renv_ <- function( } if (is.null(lockfile)) { - lockfile <- attachment::create_renv_for_prod( + lockfile <- attachment_create_renv_for_prod( path = source_folder, output = file.path(output_dir, "renv.lock.prod") ) @@ -53,7 +43,7 @@ add_dockerfile_with_renv_ <- function( overwrite = TRUE ) - socle <- dockerfiler::dock_from_renv( + socle <- dockerfiler_dock_from_renv( lockfile = lockfile, distro = distro, FROM = FROM, @@ -66,7 +56,10 @@ add_dockerfile_with_renv_ <- function( socle$write(as = file.path(output_dir, "Dockerfile_base")) - my_dock <- dockerfiler::Dockerfile$new(FROM = paste0(golem::get_golem_name(), "_base")) + my_dock <- dockerfiler_Dockerfile()$new( + FROM = paste0(golem::get_golem_name(), + "_base" + )) my_dock$COPY("renv.lock.prod", "renv.lock") diff --git a/R/boostrap_fs.R b/R/boostrap_fs.R new file mode 100644 index 00000000..9b022bf0 --- /dev/null +++ b/R/boostrap_fs.R @@ -0,0 +1,82 @@ +# All the fns here check that {fs} is installed +# before doing anything. +check_fs_installed <- function() { + rlang::check_installed( + "fs", + reason = "for file & directory manipulation.\nYou can install all {golem} dev dependencies with `golem::install_dev_deps()`." + ) +} + +fs_dir_exists <- function(path) { + check_fs_installed() + fs::dir_exists(path) +} + +fs_dir_create <- function( + path, + ..., + mode = "u=rwx,go=rx", + recurse = TRUE, + recursive +) { + check_fs_installed() + fs::dir_create( + path, + ..., + mode = mode, + recurse = recurse, + recursive = recursive + ) +} + + +fs_file_create <- function(where) { + check_fs_installed() + fs::file_create(where) +} + +fs_file_delete <- function(path) { + check_fs_installed() + fs::file_delete(path) +} + +fs_file_exists <- function(path) { + check_fs_installed() + fs::file_exists(path) +} + +fs_path_abs <- function(path) { + check_fs_installed() + fs::path_abs(path) +} + +fs_path <- function(..., ext = "") { + check_fs_installed() + fs::path(..., ext = ext) +} + +fs_file_copy <- function( + path, + new_path, + overwrite = FALSE +) { + check_fs_installed() + fs::file_copy( + path = path, + new_path = new_path, + overwrite + ) +} + +fs_dir_copy <- function( + path, + new_path, + overwrite = FALSE +) { + check_fs_installed() + fs::dir_copy( + path, + new_path, + overwrite + ) +} diff --git a/R/bootstrap_attachment.R b/R/bootstrap_attachment.R new file mode 100644 index 00000000..08e65c16 --- /dev/null +++ b/R/bootstrap_attachment.R @@ -0,0 +1,23 @@ +# All the fns here check that {attachment} is installed +# before doing anything. +check_attachment_installed <- function() { + rlang::check_installed( + "attachment", + version = "0.2.5", + reason = "to build a Dockerfile." + ) +} + +attachment_create_renv_for_prod <- function( + path = ".", + output = "renv.lock.prod", + dev_pkg = "remotes", + ... +) { + attachment::create_renv_for_prod( + path = path, + output = output, + dev_pkg = dev_pkg, + ... + ) +} diff --git a/R/bootstrap_dockerfiler.R b/R/bootstrap_dockerfiler.R new file mode 100644 index 00000000..5dd79aad --- /dev/null +++ b/R/bootstrap_dockerfiler.R @@ -0,0 +1,68 @@ +# All the fns here check that {dockerfiler} is installed +# before doing anything. +check_dockerfiler_installed <- function() { + rlang::check_installed( + "dockerfiler", + version = "0.2.0", + reason = "to build a Dockerfile." + ) +} + +dockerfiler_dock_from_renv <- function( + lockfile = "renv.lock", + distro = "focal", + FROM = "rocker/r-base", + AS = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + extra_sysreqs = NULL +) { + check_dockerfiler_installed() + dockerfiler::dock_from_renv( + lockfile = lockfile, + distro = distro, + FROM = FROM, + AS = AS, + sysreqs = sysreqs, + repos = repos, + expand = expand, + extra_sysreqs = extra_sysreqs + ) +} + +dockerfiler_dock_from_desc <- function( + path = "DESCRIPTION", + FROM = paste0( + "rocker/r-ver:", + R.Version()$major, + ".", + R.Version()$minor + ), + AS = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + update_tar_gz = TRUE, + build_from_source = TRUE, + extra_sysreqs = NULL +) { + check_dockerfiler_installed() + dockerfiler::dock_from_desc( + path = path, + FROM = FROM, + AS = AS, + sysreqs = sysreqs, + repos = repos, + expand = expand, + update_tar_gz = update_tar_gz, + build_from_source = build_from_source, + extra_sysreqs = extra_sysreqs + ) +} + + +dockerfiler_Dockerfile <- function() { + check_dockerfiler_installed() + dockerfiler::Dockerfile +} diff --git a/R/bootstrap_pkgload.R b/R/bootstrap_pkgload.R new file mode 100644 index 00000000..b4db04cc --- /dev/null +++ b/R/bootstrap_pkgload.R @@ -0,0 +1,37 @@ +# All the fns here check that {pkgload} is installed +# before doing anything. +check_pkgload_installed <- function() { + rlang::check_installed( + "pkgload", + reason = "to load the package." + ) +} + +pkgload_load_all <- function( + path = ".", + reset = TRUE, + compile = NA, + attach = TRUE, + export_all = TRUE, + export_imports = export_all, + helpers = TRUE, + attach_testthat = uses_testthat(path), + quiet = NULL, + recompile = FALSE, + warn_conflicts = TRUE +) { + check_roxygen2_installed() + pkgload::load_all( + path = path, + reset = reset, + compile = compile, + attach = attach, + export_all = export_all, + export_imports = export_imports, + helpers = helpers, + attach_testthat = attach_testthat, + quiet = quiet, + recompile = recompile, + warn_conflicts = warn_conflicts + ) +} diff --git a/R/bootstrap_roxygen2.R b/R/bootstrap_roxygen2.R new file mode 100644 index 00000000..e836517c --- /dev/null +++ b/R/bootstrap_roxygen2.R @@ -0,0 +1,23 @@ +# All the fns here check that {roxygen2} is installed +# before doing anything. +check_roxygen2_installed <- function() { + rlang::check_installed( + "roxygen2", + reason = "to document the package." + ) +} + +roxygen2_roxygenise <- function( + package.dir = ".", + roclets = NULL, + load_code = NULL, + clean = FALSE +) { + check_roxygen2_installed() + roxygen2::roxygenise( + package.dir = package.dir, + roclets = roclets, + load_code = load_code, + clean = clean + ) +} diff --git a/R/bootstrap_usethis.R b/R/bootstrap_usethis.R new file mode 100644 index 00000000..a153d78b --- /dev/null +++ b/R/bootstrap_usethis.R @@ -0,0 +1,116 @@ + +# All the fns here check that {usethis} is installed +# before doing anything. +check_usethis_installed <- function(reason = "for project and file manipulation.") { + rlang::check_installed( + "usethis", + version = "1.6.0", + reason = reason + ) +} + +usethis_use_build_ignore <- function( + files, + escape = TRUE +) { + check_usethis_installed( + reason = "to ignore files in the build." + ) + usethis::use_build_ignore( + files, + escape + ) +} +usethis_use_package <- function( + package, + type = "Imports", + min_version = NULL +) { + check_usethis_installed( + reason = "to add dependencies to DESCRIPTION." + ) + usethis::use_package( + package, + type, + min_version + ) +} + +usethis_create_project <- function( + path, + rstudio = rstudioapi::isAvailable(), + open = rlang::is_interactive() +) { + check_usethis_installed( + reason = "to create a project." + ) + usethis::create_project( + path, + rstudio, + open + ) +} +usethis_use_latest_dependencies <- function( + overwrite = FALSE, + source = c("local", "CRAN") +) { + check_usethis_installed( + reason = "to set dependency version." + ) + usethis::use_latest_dependencies( + overwrite, + source + ) +} + +usethis_proj_set <- function( + path = ".", + force = FALSE +) { + check_usethis_installed( + reason = "to set project." + ) + usethis::proj_set( + path, + force + ) +} +usethis_use_testthat <- function( + edition = NULL, + parallel = FALSE +) { + check_usethis_installed( + reason = "to add {testthat} infrastructure." + ) + usethis::use_testthat( + edition, + parallel + ) +} +usethis_use_test <- function( + name = NULL, + open = rlang::is_interactive() +) { + check_usethis_installed( + reason = "to add tests." + ) + usethis::use_test( + name, + open + ) +} + +usethis_use_spell_check <- function( + vignettes = TRUE, + lang = "en-US", + error = FALSE +) { + check_usethis_installed( + reason = "to add spellcheck." + ) + usethis::use_spell_check( + vignettes, + lang, + error + ) +} diff --git a/R/fs_boostrap.R b/R/fs_boostrap.R deleted file mode 100644 index 55ab5b83..00000000 --- a/R/fs_boostrap.R +++ /dev/null @@ -1,82 +0,0 @@ -# All the fns here check that {fs} is installed -# before doing anything. -check_fs_installed <- function() { - rlang::check_installed( - "fs", - reason = "for file & directory manipulation.\nYou can install all {golem} dev dependencies with `golem::install_dev_deps()`." - ) -} - -fs_dir_exists <- function(path) { - check_fs_installed() - fs::dir_exists(path) -} - -fs_dir_create <- function( - path, - ..., - mode = "u=rwx,go=rx", - recurse = TRUE, - recursive -) { - check_fs_installed() - fs::dir_create( - path, - ..., - mode = mode, - recurse = recurse, - recursive = recursive - ) -} - - -fs_file_create <- function(where) { - check_fs_installed() - fs::file_create(where) -} - -fs_file_delete <- function(path) { - check_fs_installed() - fs::file_delete(path) -} - -fs_file_exists <- function(path) { - check_fs_installed() - fs::file_exists(path) -} - -fs_path_abs <- function(path) { - check_fs_installed() - fs::path_abs(path) -} - -fs_path <- function(..., ext = "") { - check_fs_installed() - fs::path(..., ext = ext) -} - -fs_file_copy <- function( - path, - new_path, - overwrite = FALSE -) { - check_fs_installed() - fs::file_copy( - path = path, - new_path = new_path, - overwrite - ) -} - -fs_dir_copy <- function( - path, - new_path, - overwrite = FALSE -) { - check_fs_installed() - fs::dir_copy( - path, - new_path, - overwrite - ) -} diff --git a/R/modules_fn.R b/R/modules_fn.R index 557e1089..a393b0ed 100644 --- a/R/modules_fn.R +++ b/R/modules_fn.R @@ -256,18 +256,12 @@ use_module_test <- function( } # We need both testthat, usethis & fs - rlang::check_installed( - "usethis", - "to build the test structure." - ) + rlang::check_installed( "testthat", "to build the test structure." ) - rlang::check_installed( - "fs" - ) - + old <- setwd(fs_path_abs(pkg)) on.exit(setwd(old)) diff --git a/R/reload.R b/R/reload.R index b124da96..3f16d7f4 100644 --- a/R/reload.R +++ b/R/reload.R @@ -106,13 +106,12 @@ document_and_reload <- function( check_name_consistency(pkg) rlang::check_installed("pkgload") - rlang::check_installed("roxygen2") if (rstudioapi::isAvailable() & rstudioapi::hasFun("documentSaveAll")) { rstudioapi::documentSaveAll() } roxed <- try({ - roxygen2::roxygenise( + roxygen2_roxygenise( package.dir = pkg, roclets = roclets, load_code = load_code, @@ -127,7 +126,7 @@ document_and_reload <- function( return(invisible(FALSE)) } loaded <- try({ - pkgload::load_all( + pkgload_load_all( pkg, export_all = export_all, helpers = helpers, diff --git a/R/use_utils.R b/R/use_utils.R index ef2c1f46..ebe09768 100644 --- a/R/use_utils.R +++ b/R/use_utils.R @@ -135,10 +135,6 @@ use_utils <- function( folder_name, pkg = get_golem_wd() ) { - rlang::check_installed( - "fs", - reason = "for file manipulation." - ) old <- setwd( fs_path_abs(pkg) diff --git a/R/usethis_bootstrap.R b/R/usethis_bootstrap.R deleted file mode 100644 index 1e513da5..00000000 --- a/R/usethis_bootstrap.R +++ /dev/null @@ -1,116 +0,0 @@ - -# All the fns here check that {usethis} is installed -# before doing anything. -check_usethis_installed <- function(reason = "for project and file manipulation.") { - rlang::check_installed( - "usethis", - version = "1.6.0", - reason = reason - ) -} - -usethis_use_build_ignore <- function( - files, - escape = TRUE -) { - check_usethis_installed( - reason = "to ignore files in the build." - ) - usethis::use_build_ignore( - files, - escape - ) -} -usethis_use_package <- function( - package, - type = "Imports", - min_version = NULL -) { - check_usethis_installed( - reason = "to add dependencies to DESCRIPTION." - ) - usethis::use_package( - package, - type, - min_version - ) -} - -usethis_create_project <- function( - path, - rstudio = rstudioapi::isAvailable(), - open = rlang::is_interactive() -) { - check_usethis_installed( - reason = "to create a project." - ) - usethis::create_project( - path, - rstudio, - open - ) -} -usethis_use_latest_dependencies <- function( - overwrite = FALSE, - source = c("local", "CRAN") -) { - check_usethis_installed( - reason = "to set dependency version." - ) - usethis::use_latest_dependencies( - overwrite, - source - ) -} - -usethis_proj_set <- function( - path = ".", - force = FALSE -) { - check_usethis_installed( - reason = "to set project." - ) - usethis::proj_set( - path, - force - ) -} -usethis_use_testthat <- function( - edition = NULL, - parallel = FALSE -) { - check_usethis_installed( - reason = "to add {testthat} infrastructure." - ) - usethis::use_testthat( - edition, - parallel - ) -} -usethis_use_test <- function( - name = NULL, - open = rlang::is_interactive() -) { - check_usethis_installed( - reason = "to add tests." - ) - usethis::use_test( - name, - open - ) -} - -usethis_use_spell_check <- function( - vignettes = TRUE, - lang = "en-US", - error = FALSE -) { - check_usethis_installed( - reason = "to add spellcheck." - ) - usethis::use_spell_check( - vignettes, - lang, - error - ) -} From 0313b5919a1290545e2cc2d9106a9aa7022edd87 Mon Sep 17 00:00:00 2001 From: Colin Fay Date: Fri, 14 Oct 2022 19:56:19 +0200 Subject: [PATCH 06/55] feat: Make cat functions conditional to an options (#934) --- R/add_files.R | 2 +- R/bootstrap_pkgload.R | 3 + R/create_golem.R | 4 +- R/disable_autoload.R | 2 +- R/reload.R | 4 +- R/set_golem_options.R | 4 +- R/utils.R | 100 +++++++++++++++++------ tests/testthat/helper-config.R | 4 +- tests/testthat/test-add_deploy_helpers.R | 62 ++++++++------ tests/testthat/test-add_modules.R | 5 +- tests/testthat/test-desc.R | 23 +++--- tests/testthat/test-extra_sysreqs.R | 6 +- tests/testthat/test-make_dev.R | 5 +- tests/testthat/test-test_helpers.R | 14 +++- tests/testthat/test-zzzzzzzzzz.R | 4 +- 15 files changed, 163 insertions(+), 79 deletions(-) diff --git a/R/add_files.R b/R/add_files.R index 08a420ea..1b964d21 100644 --- a/R/add_files.R +++ b/R/add_files.R @@ -512,7 +512,7 @@ add_sass_file <- function( name = name ) - cli_alert_info( + cat_green_tick( "After running the compilation, your CSS file will be automatically link in `golem_add_external_resources()`." ) } else { diff --git a/R/bootstrap_pkgload.R b/R/bootstrap_pkgload.R index b4db04cc..3c90630a 100644 --- a/R/bootstrap_pkgload.R +++ b/R/bootstrap_pkgload.R @@ -7,6 +7,9 @@ check_pkgload_installed <- function() { ) } +uses_testthat <- getFromNamespace( "uses_testthat", "pkgload" ) + + pkgload_load_all <- function( path = ".", reset = TRUE, diff --git a/R/create_golem.R b/R/create_golem.R index 12bc8db6..fb77355f 100644 --- a/R/create_golem.R +++ b/R/create_golem.R @@ -113,7 +113,9 @@ create_golem <- function( path = path_to_golem, open = FALSE ) - here::set_here(path_to_golem) + if (!file.exists(".here")){ + here::set_here(path_to_golem) + } cat_green_tick("Created package directory") } diff --git a/R/disable_autoload.R b/R/disable_autoload.R index 64215656..a984b02c 100644 --- a/R/disable_autoload.R +++ b/R/disable_autoload.R @@ -20,7 +20,7 @@ disable_autoload <- function(pkg = get_golem_wd()) { "_disable_autoload.R already exists, skipping its creation." ) } else { - cli::cat_rule("Creating _disable_autoload.R") + cat_rule("Creating _disable_autoload.R") write( "# Disabling shiny autoload\n\n# See ?shiny::loadSupport for more information", fls diff --git a/R/reload.R b/R/reload.R index 3f16d7f4..2bb9e51f 100644 --- a/R/reload.R +++ b/R/reload.R @@ -119,7 +119,7 @@ document_and_reload <- function( ) }) if (attempt::is_try_error(roxed)) { - cli::cat_rule( + cat_rule( "Error documenting your package" ) dialog_if_has("Alert", "Error documenting your package") @@ -136,7 +136,7 @@ document_and_reload <- function( }) if (attempt::is_try_error(loaded)) { - cli::cat_rule( + cat_rule( "Error loading your package" ) dialog_if_has("Alert", "Error loading your package") diff --git a/R/set_golem_options.R b/R/set_golem_options.R index 28ddd90c..2a965ae9 100644 --- a/R/set_golem_options.R +++ b/R/set_golem_options.R @@ -48,7 +48,7 @@ set_golem_options <- function( # golem_install_dev_pkg() function if (talkative) { - cli::cat_rule( + cat_rule( "Setting {golem} options in `golem-config.yml`" ) } @@ -90,7 +90,7 @@ set_golem_options <- function( # This part is for {usethis} and {here} if (talkative) { - cli::cat_rule( + cat_rule( "Setting {usethis} project as `golem_wd`" ) } diff --git a/R/utils.R b/R/utils.R index 2246d5ea..f6498796 100644 --- a/R/utils.R +++ b/R/utils.R @@ -113,29 +113,55 @@ remove_comments <- function(file) { #' @importFrom cli cat_bullet cat_green_tick <- function(...) { - cat_bullet( - ..., - bullet = "tick", - bullet_col = "green" - ) + do_if_unquiet({ + cat_bullet( + ..., + bullet = "tick", + bullet_col = "green" + ) + }) } #' @importFrom cli cat_bullet cat_red_bullet <- function(...) { - cat_bullet( - ..., - bullet = "bullet", - bullet_col = "red" - ) + do_if_unquiet({ + cli::cat_bullet( + ..., + bullet = "bullet", + bullet_col = "red" + ) + }) } #' @importFrom cli cat_bullet cat_info <- function(...) { - cat_bullet( - ..., - bullet = "arrow_right", - bullet_col = "grey" - ) + do_if_unquiet({ + cli::cat_bullet( + ..., + bullet = "arrow_right", + bullet_col = "grey" + ) + }) +} + +cat_rule <- function( + ... +) { + do_if_unquiet({ + cli::cat_rule( + ... + ) + }) +} + +cat_line <- function( + ... +) { + do_if_unquiet({ + cli::cat_line( + ... + ) + }) } cat_exists <- function(where) { @@ -160,8 +186,10 @@ cat_dir_necessary <- function() { } cat_start_download <- function() { - cat_line("") - cat_rule("Initiating file download") + do_if_unquiet({ + cat_line("") + cat_rule("Initiating file download") + }) } cat_downloaded <- function( @@ -178,8 +206,10 @@ cat_downloaded <- function( } cat_start_copy <- function() { - cat_line("") - cat_rule("Copying file") + do_if_unquiet({ + cat_line("") + cat_rule("Copying file") + }) } cat_copied <- function( @@ -314,13 +344,15 @@ after_creation_message_html_template <- function( dir, name ) { - cat_line("") - cat_rule("To use this html file as a template, add the following code in your UI:") - cat_line(darkgrey("htmlTemplate(")) - cat_line(darkgrey(sprintf(' app_sys("app/www/%s.html"),', file_path_sans_ext(name)))) - cat_line(darkgrey(" body = tagList()")) - cat_line(darkgrey(" # add here other template arguments")) - cat_line(darkgrey(")")) + do_if_unquiet({ + cat_line("") + cat_rule("To use this html file as a template, add the following code in your UI:") + cat_line(darkgrey("htmlTemplate(")) + cat_line(darkgrey(sprintf(' app_sys("app/www/%s.html"),', file_path_sans_ext(name)))) + cat_line(darkgrey(" body = tagList()")) + cat_line(darkgrey(" # add here other template arguments")) + cat_line(darkgrey(")")) + }) } file_created_dance <- function( @@ -447,3 +479,19 @@ check_name_length <- function(name) { ) ) } + +do_if_unquiet <- function( + expr +){ + if( + ! getOption( + "golem.quiet", + getOption( + "usethis.quiet", + default = FALSE + ) + ) + ){ + force(expr) + } +} \ No newline at end of file diff --git a/tests/testthat/helper-config.R b/tests/testthat/helper-config.R index 52f85e55..f50b9073 100644 --- a/tests/testthat/helper-config.R +++ b/tests/testthat/helper-config.R @@ -81,7 +81,9 @@ rand_name <- function() { withr::with_dir(pkg, { # Some weird things with {here} unloadNamespace("here") - here::set_here(".") + if (!file.exists(".here")){ + here::set_here(path_to_golem) + } set_golem_options() usethis::proj_set(pkg) orig_test <- set_golem_wd( diff --git a/tests/testthat/test-add_deploy_helpers.R b/tests/testthat/test-add_deploy_helpers.R index b798603f..0bbe2181 100644 --- a/tests/testthat/test-add_deploy_helpers.R +++ b/tests/testthat/test-add_deploy_helpers.R @@ -12,9 +12,14 @@ test_that("add_dockerfiles", { burn_after_reading( "Dockerfile", { - output <- testthat::capture_output( - fun(pkg = pkg, sysreqs = FALSE, open = FALSE) + withr::with_options( + c("golem.quiet" = FALSE),{ + output <- testthat::capture_output( + fun(pkg = pkg, sysreqs = FALSE, open = FALSE) + ) + } ) + expect_exists("Dockerfile") test <- stringr::str_detect( output, @@ -37,27 +42,29 @@ test_that("add_dockerfiles repos variation", { burn_after_reading( c("Dockerfile1", "Dockerfile2"), { - output1 <- testthat::capture_output( - fun( - pkg = pkg, - sysreqs = FALSE, - open = FALSE, - repos = "https://cran.rstudio.com/", - output = "Dockerfile1" + withr::with_options( + c("golem.quiet" = FALSE),{ + output1 <- testthat::capture_output( + fun( + pkg = pkg, + sysreqs = FALSE, + open = FALSE, + repos = "https://cran.rstudio.com/", + output = "Dockerfile1" + ) ) - ) - output2 <- testthat::capture_output( - fun( - pkg = pkg, - sysreqs = FALSE, - open = FALSE, - repos = c("https://cran.rstudio.com/"), - output = "Dockerfile2" + output2 <- testthat::capture_output( + fun( + pkg = pkg, + sysreqs = FALSE, + open = FALSE, + repos = c("https://cran.rstudio.com/"), + output = "Dockerfile2" + ) ) - ) - expect_exists("Dockerfile1") - expect_exists("Dockerfile2") - + expect_exists("Dockerfile1") + expect_exists("Dockerfile2") + }) test1 <- stringr::str_detect( output1, @@ -91,12 +98,15 @@ test_that("add_rstudio_files", { burn_after_reading( "app.R", { - output <- testthat::capture_output( - fun( - pkg = pkg, - open = FALSE - ) + withr::with_options( + c("golem.quiet" = FALSE),{ + output <- testthat::capture_output( + fun( + pkg = pkg, + open = FALSE + ) ) + }) expect_exists("app.R") test <- stringr::str_detect( output, diff --git a/tests/testthat/test-add_modules.R b/tests/testthat/test-add_modules.R index a1584aef..af70b65b 100644 --- a/tests/testthat/test-add_modules.R +++ b/tests/testthat/test-add_modules.R @@ -15,7 +15,10 @@ test_that("add_module", { lapply(tools::file_ext(script), function(x) testthat::expect_equal(x, "R")) ## Test message of function remove_file("R/mod_output.R") - output <- testthat::capture_output(add_module("output", open = FALSE)) + withr::with_options( + c("golem.quiet" = FALSE),{ + output <- testthat::capture_output(add_module("output", open = FALSE)) + }) expect_true( stringr::str_detect(output, "File created at R/mod_output.R") ) diff --git a/tests/testthat/test-desc.R b/tests/testthat/test-desc.R index 7af2b91f..86ec958b 100644 --- a/tests/testthat/test-desc.R +++ b/tests/testthat/test-desc.R @@ -1,17 +1,20 @@ test_that("desc works", { with_dir(pkg, { - output <- capture_output( - fill_desc( - fakename, - "newtitle", - "Newdescription.", - "firstname", - "lastname", - "name@test.com", - "http://repo_url.com" + withr::with_options( + c("golem.quiet" = FALSE),{ + output <- capture_output( + fill_desc( + fakename, + "newtitle", + "Newdescription.", + "firstname", + "lastname", + "name@test.com", + "http://repo_url.com" + ) ) - ) + }) add_desc <- c( fakename, "newtitle", diff --git a/tests/testthat/test-extra_sysreqs.R b/tests/testthat/test-extra_sysreqs.R index d0e47254..286f0999 100644 --- a/tests/testthat/test-extra_sysreqs.R +++ b/tests/testthat/test-extra_sysreqs.R @@ -13,7 +13,9 @@ test_that("test extra sysreqs", { burn_after_reading( "Dockerfile", { - output <- testthat::capture_output( + withr::with_options( + c("golem.quiet" = FALSE),{ + output <- testthat::capture_output( fun( pkg = pkg, sysreqs = FALSE, @@ -22,7 +24,7 @@ test_that("test extra sysreqs", { output = "Dockerfile" ) ) - + }) expect_exists("Dockerfile") test <- stringr::str_detect( output, diff --git a/tests/testthat/test-make_dev.R b/tests/testthat/test-make_dev.R index bbf46547..5f736b7a 100644 --- a/tests/testthat/test-make_dev.R +++ b/tests/testthat/test-make_dev.R @@ -60,7 +60,10 @@ test_that("test print_dev", { test_that("test browser_button", { - output <- capture_output_lines(browser_button()) + withr::with_options( + c("golem.quiet" = FALSE),{ + output <- capture_output_lines(browser_button()) + }) expect_true( grepl('actionButton\\("browser", "browser"\\)', output[2]) ) diff --git a/tests/testthat/test-test_helpers.R b/tests/testthat/test-test_helpers.R index c1e4ccad..82aa04c2 100644 --- a/tests/testthat/test-test_helpers.R +++ b/tests/testthat/test-test_helpers.R @@ -1,13 +1,19 @@ test_that("test expect_shinytag", { with_dir(pkg, { - expect_equal(capture_output(expect_shinytag(favicon("jean"))), "") - expect_error(expect_shinytag("pierre")) + withr::with_options( + c("golem.quiet" = FALSE),{ + expect_equal(capture_output(expect_shinytag(favicon("jean"))), "") + expect_error(expect_shinytag("pierre")) + }) }) }) test_that("test expect_shinytaglist", { with_dir(pkg, { - expect_equal(capture_output(expect_shinytaglist(shiny::tagList())), "") - expect_error(expect_shinytaglist("test")) + withr::with_options( + c("golem.quiet" = FALSE),{ + expect_equal(capture_output(expect_shinytaglist(shiny::tagList())), "") + expect_error(expect_shinytaglist("test")) + }) }) }) diff --git a/tests/testthat/test-zzzzzzzzzz.R b/tests/testthat/test-zzzzzzzzzz.R index 82aa1a70..b5bf278c 100644 --- a/tests/testthat/test-zzzzzzzzzz.R +++ b/tests/testthat/test-zzzzzzzzzz.R @@ -4,7 +4,9 @@ try({ usethis::proj_set(orig_test) } if (exists("pkg")) { - unlink(pkg, TRUE, TRUE) + try({ + unlink(pkg, TRUE, TRUE) + }) } options("usethis.quiet" = old_usethis.quiet) From 9b072a51480ed9b7f79aac06c96b219917dc1b10 Mon Sep 17 00:00:00 2001 From: Colin Fay Date: Fri, 14 Oct 2022 19:57:52 +0200 Subject: [PATCH 07/55] doc: NEWS update & version bump --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index e44fbbda..14b49f15 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: golem Title: A Framework for Robust Shiny Applications -Version: 0.3.4.9001 +Version: 0.3.4.9002 Authors@R: c(person(given = "Colin", family = "Fay", diff --git a/NEWS.md b/NEWS.md index d39b15dc..91c61c1e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -23,6 +23,8 @@ + `{golem}` now depends on `{rlang}` version >= 1.0.0 ++ Functions that print to the console are now quiet if `options("golem.quiet" = TRUE)`, #793 + ## Bug fix + The message after htmlTemplate creation now suggests to add in the UI, not only in app_ui.R (#861) From 8eb0719a6ff4c511a1916783ca2b4f573c70d6b7 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 12 Oct 2022 21:27:59 +0200 Subject: [PATCH 08/55] chore: version bump We needed to release a version for golem to stay on CRAN but a real release was not ready, hence a small 0.3.4 --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 3f134dd0..6bb804f7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,10 @@ Update in the tests for CRAN (commented a test that made new version of testthat Update in the tests for CRAN (skip not installed + examples). +# golem 0.3.4. + +This version has a small internal change in the tests, so that it can stay on CRAN. + # golem 0.3.3 ## New functions From 1238ce95276a2b10c1bea6c921335bf1ac5ce21f Mon Sep 17 00:00:00 2001 From: Colin Fay Date: Wed, 12 Oct 2022 21:23:55 +0200 Subject: [PATCH 09/55] chore: merging changes from CRAN upload (#928) --- R/add_dockerfiles.R | 2 +- man/dockerfiles.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index f8cce15d..c19d4bcb 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -67,7 +67,7 @@ talk_once <- function(.f, msg = "") { #' } #' # Crete a 'deploy' folder containing everything needed to deploy #' # the golem using docker based on {renv} -#' if (interactive() & requireNamespace("dockerfiler")) { +#' if (interactive()) { #' add_dockerfile_with_renv( #' # lockfile = "renv.lock", # uncomment to use existing renv.lock file #' output_dir = "deploy" diff --git a/man/dockerfiles.Rd b/man/dockerfiles.Rd index a8a7738e..97a8a023 100644 --- a/man/dockerfiles.Rd +++ b/man/dockerfiles.Rd @@ -172,7 +172,7 @@ if (interactive() & requireNamespace("dockerfiler")) { } # Crete a 'deploy' folder containing everything needed to deploy # the golem using docker based on {renv} -if (interactive() & requireNamespace("dockerfiler")) { +if (interactive()) { add_dockerfile_with_renv( # lockfile = "renv.lock", # uncomment to use existing renv.lock file output_dir = "deploy" From 4f0eb33cfe492cacbfb30041b6b929f03658bc33 Mon Sep 17 00:00:00 2001 From: Colin Fay Date: Wed, 12 Oct 2022 22:11:39 +0200 Subject: [PATCH 10/55] feat: removed {usethis} hard dep (#929) --- DESCRIPTION | 6 +- NAMESPACE | 7 --- R/add_dockerfiles.R | 22 ++------ R/add_dockerfiles_renv.R | 2 +- R/add_r_files.R | 2 +- R/add_rstudio_files.R | 9 +-- R/create_golem.R | 17 ++++-- R/modules_fn.R | 2 +- R/set_golem_options.R | 3 +- R/use_recommended.R | 15 +---- R/use_utils.R | 5 +- R/usethis_bootstrap.R | 116 +++++++++++++++++++++++++++++++++++++++ 12 files changed, 149 insertions(+), 57 deletions(-) create mode 100644 R/usethis_bootstrap.R diff --git a/DESCRIPTION b/DESCRIPTION index c65fbc04..4463bffe 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -55,12 +55,10 @@ Imports: crayon, desc, here, - fs, htmltools, rlang (>= 1.0.0), rstudioapi, shiny (>= 1.5.0), - usethis (>= 1.6.0), utils, yaml Suggests: @@ -83,7 +81,9 @@ Suggests: tools, withr, attachment (>= 0.2.5), - renv + renv, + usethis (>= 1.6.0), + fs VignetteBuilder: knitr Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 1f59daf5..7cdfebe7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -111,13 +111,6 @@ importFrom(shiny,addResourcePath) importFrom(shiny,getShinyOption) importFrom(shiny,includeScript) importFrom(shiny,tags) -importFrom(usethis,create_project) -importFrom(usethis,proj_set) -importFrom(usethis,use_build_ignore) -importFrom(usethis,use_latest_dependencies) -importFrom(usethis,use_package) -importFrom(usethis,use_spell_check) -importFrom(usethis,use_testthat) importFrom(utils,capture.output) importFrom(utils,file.edit) importFrom(utils,getFromNamespace) diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index c19d4bcb..490c10a1 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -9,17 +9,6 @@ talk_once <- function(.f, msg = "") { } } -talk_once <- function(.f, msg = "") { - talk <- TRUE - function(...) { - if (talk) { - talk <<- FALSE - cat_red_bullet(msg) - } - .f(...) - } -} - #' Create a Dockerfile for your App #' #' Build a container containing your Shiny App. `add_dockerfile()` and `add_dockerfile_with_renv()` and `add_dockerfile_with_renv()` creates @@ -55,7 +44,6 @@ talk_once <- function(.f, msg = "") { #' @export #' @rdname dockerfiles #' -#' @importFrom usethis use_build_ignore #' @importFrom desc desc_get_deps #' @importFrom rstudioapi navigateToFile isAvailable hasFun #' @@ -162,7 +150,9 @@ add_dockerfile_ <- talk_once( where <- fs_path(pkg, output) - usethis::use_build_ignore(basename(where)) + usethis_use_build_ignore( + basename(where) + ) dock <- dockerfiler::dock_from_desc( path = path, @@ -271,7 +261,7 @@ add_dockerfile_shinyproxy_ <- talk_once( ) where <- fs_path(pkg, output) - usethis::use_build_ignore(output) + usethis_use_build_ignore(output) dock <- dockerfiler::dock_from_desc( path = path, @@ -374,7 +364,7 @@ add_dockerfile_heroku_ <- talk_once( ) where <- fs_path(pkg, output) - usethis::use_build_ignore(output) + usethis_use_build_ignore(output) dock <- dockerfiler::dock_from_desc( path = path, @@ -437,7 +427,7 @@ add_dockerfile_heroku_ <- talk_once( try(file.edit(output)) } } - usethis::use_build_ignore(files = output) + usethis_use_build_ignore(files = output) return(invisible(dock)) }, " diff --git a/R/add_dockerfiles_renv.R b/R/add_dockerfiles_renv.R index b9c59503..93f5d3fb 100644 --- a/R/add_dockerfiles_renv.R +++ b/R/add_dockerfiles_renv.R @@ -37,7 +37,7 @@ add_dockerfile_with_renv_ <- function( # add output_dir in Rbuildignore if the output is inside the golem if (normalizePath(dirname(output_dir)) == normalizePath(source_folder)) { - usethis::use_build_ignore(output_dir) + usethis_use_build_ignore(output_dir) } if (is.null(lockfile)) { diff --git a/R/add_r_files.R b/R/add_r_files.R index 1e6e66fa..a4bcb24f 100644 --- a/R/add_r_files.R +++ b/R/add_r_files.R @@ -68,7 +68,7 @@ add_r_files <- function( } if (with_test) { - usethis::use_test( + usethis_use_test( basename( file_path_sans_ext( where diff --git a/R/add_rstudio_files.R b/R/add_rstudio_files.R index f756e1e1..44955959 100644 --- a/R/add_rstudio_files.R +++ b/R/add_rstudio_files.R @@ -1,6 +1,5 @@ #' @importFrom utils capture.output #' @importFrom cli cat_bullet -#' @importFrom usethis use_build_ignore use_package add_rstudio_files <- function( pkg, open, @@ -18,8 +17,6 @@ add_rstudio_files <- function( reason = "to deploy on RStudio products." ) - rlang::check_installed("usethis") - disable_autoload( pkg = pkg ) @@ -31,8 +28,8 @@ add_rstudio_files <- function( write(..., here, append = TRUE) } - use_build_ignore(basename(where)) - use_build_ignore("rsconnect") + usethis_use_build_ignore(basename(where)) + usethis_use_build_ignore("rsconnect") write_there("# Launch the ShinyApp (Do not remove this comment)") write_there("# To deploy, run: rsconnect::deployApp()") write_there("# Or use the blue button on top of this file") @@ -47,7 +44,7 @@ add_rstudio_files <- function( ) # We add {pkgload} as a dep because it's required to deploy on Connect & stuff - usethis::use_package("pkgload") + usethis_use_package("pkgload") cat_created(where) cat_line("To deploy, run:") diff --git a/R/create_golem.R b/R/create_golem.R index 5f4b5651..12bc8db6 100644 --- a/R/create_golem.R +++ b/R/create_golem.R @@ -57,7 +57,6 @@ replace_package_name <- function( #' @importFrom cli cat_rule cat_line #' @importFrom utils getFromNamespace #' @importFrom rstudioapi isAvailable openProject hasFun -#' @importFrom usethis use_latest_dependencies create_project #' @importFrom yaml write_yaml #' #' @export @@ -81,7 +80,15 @@ create_golem <- function( if (check_name) { cat_rule("Checking package name") - getFromNamespace("check_package_name", "usethis")(package_name) + rlang::check_installed( + "usethis", + version = "1.6.0", + reason = "to check the package name." + ) + getFromNamespace( + "check_package_name", + "usethis" + )(package_name) cat_green_tick("Valid package name") } @@ -102,9 +109,9 @@ create_golem <- function( } } else { cat_rule("Creating dir") - usethis::create_project( + usethis_create_project( path = path_to_golem, - open = FALSE, + open = FALSE ) here::set_here(path_to_golem) cat_green_tick("Created package directory") @@ -188,7 +195,7 @@ create_golem <- function( old <- setwd(path_to_golem) - use_latest_dependencies() + usethis_use_latest_dependencies() # No .Rprofile for now # cat_rule("Appending .Rprofile") diff --git a/R/modules_fn.R b/R/modules_fn.R index 9204494e..c871b6cf 100644 --- a/R/modules_fn.R +++ b/R/modules_fn.R @@ -266,7 +266,7 @@ use_module_test <- function( if (!fs_dir_exists( fs_path(pkg, "tests", "testthat") )) { - usethis::use_testthat() + usethis_use_testthat() } path <- fs_path( diff --git a/R/set_golem_options.R b/R/set_golem_options.R index bf9d59e8..28ddd90c 100644 --- a/R/set_golem_options.R +++ b/R/set_golem_options.R @@ -32,7 +32,6 @@ #' #' @export #' @importFrom attempt stop_if_not -#' @importFrom usethis proj_set #' #' @return Used for side-effects for the setters, and values from the #' config in the getters. @@ -96,5 +95,5 @@ set_golem_options <- function( ) } - proj_set(golem_wd) + usethis_proj_set(golem_wd) } diff --git a/R/use_recommended.R b/R/use_recommended.R index c72d85a7..1a348a9c 100644 --- a/R/use_recommended.R +++ b/R/use_recommended.R @@ -10,7 +10,6 @@ #' @param recommended A vector of recommended packages. #' @param spellcheck Whether or not to use a spellcheck test. #' -#' @importFrom usethis use_testthat use_package #' @rdname use_recommended #' #' @export @@ -29,7 +28,7 @@ use_recommended_deps <- function( on.exit(setwd(old)) for (i in sort(recommended)) { - try(use_package(i)) + try(usethis_use_package(i)) } cat_green_tick("Dependencies added") @@ -38,7 +37,6 @@ use_recommended_deps <- function( #' @rdname use_recommended #' @export -#' @importFrom usethis use_testthat use_package use_spell_check #' @importFrom utils capture.output #' @importFrom attempt without_warning stop_if use_recommended_tests <- function( @@ -50,17 +48,12 @@ use_recommended_tests <- function( ) { old <- setwd(fs_path_abs(pkg)) - rlang::check_installed( - "fs", - reason = "for file & directory manipulation." - ) - on.exit(setwd(old)) if (!fs_dir_exists( fs_path(fs_path_abs(pkg), "tests") )) { - without_warning(use_testthat)() + without_warning(usethis_use_testthat)() } if (!requireNamespace("processx")) { stop("Please install the {processx} package to add the recommended tests.") @@ -79,13 +72,11 @@ use_recommended_tests <- function( ) if (spellcheck) { - use_spell_check( + usethis_use_spell_check( vignettes = vignettes, lang = lang, error = error ) } - - cat_green_tick("Tests added") } diff --git a/R/use_utils.R b/R/use_utils.R index e9de1af3..ef2c1f46 100644 --- a/R/use_utils.R +++ b/R/use_utils.R @@ -12,7 +12,6 @@ #' #' @importFrom cli cat_bullet #' @importFrom utils capture.output -#' @importFrom usethis use_testthat #' #' @return Used for side-effects. use_utils_ui <- function( @@ -30,7 +29,7 @@ use_utils_ui <- function( if (with_test) { if (!isTRUE(fs_dir_exists("tests"))) { - use_testthat() + usethis_use_testthat() } pth <- fs_path( pkg, @@ -82,7 +81,7 @@ use_utils_server <- function( if (with_test) { if (!isTRUE(fs_dir_exists("tests"))) { - use_testthat() + usethis_use_testthat() } pth <- fs_path( pkg, diff --git a/R/usethis_bootstrap.R b/R/usethis_bootstrap.R new file mode 100644 index 00000000..1e513da5 --- /dev/null +++ b/R/usethis_bootstrap.R @@ -0,0 +1,116 @@ + +# All the fns here check that {usethis} is installed +# before doing anything. +check_usethis_installed <- function(reason = "for project and file manipulation.") { + rlang::check_installed( + "usethis", + version = "1.6.0", + reason = reason + ) +} + +usethis_use_build_ignore <- function( + files, + escape = TRUE +) { + check_usethis_installed( + reason = "to ignore files in the build." + ) + usethis::use_build_ignore( + files, + escape + ) +} +usethis_use_package <- function( + package, + type = "Imports", + min_version = NULL +) { + check_usethis_installed( + reason = "to add dependencies to DESCRIPTION." + ) + usethis::use_package( + package, + type, + min_version + ) +} + +usethis_create_project <- function( + path, + rstudio = rstudioapi::isAvailable(), + open = rlang::is_interactive() +) { + check_usethis_installed( + reason = "to create a project." + ) + usethis::create_project( + path, + rstudio, + open + ) +} +usethis_use_latest_dependencies <- function( + overwrite = FALSE, + source = c("local", "CRAN") +) { + check_usethis_installed( + reason = "to set dependency version." + ) + usethis::use_latest_dependencies( + overwrite, + source + ) +} + +usethis_proj_set <- function( + path = ".", + force = FALSE +) { + check_usethis_installed( + reason = "to set project." + ) + usethis::proj_set( + path, + force + ) +} +usethis_use_testthat <- function( + edition = NULL, + parallel = FALSE +) { + check_usethis_installed( + reason = "to add {testthat} infrastructure." + ) + usethis::use_testthat( + edition, + parallel + ) +} +usethis_use_test <- function( + name = NULL, + open = rlang::is_interactive() +) { + check_usethis_installed( + reason = "to add tests." + ) + usethis::use_test( + name, + open + ) +} + +usethis_use_spell_check <- function( + vignettes = TRUE, + lang = "en-US", + error = FALSE +) { + check_usethis_installed( + reason = "to add spellcheck." + ) + usethis::use_spell_check( + vignettes, + lang, + error + ) +} From 9b68398dba46bc2ac6a4306188670ddec5b75e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rochette?= Date: Thu, 13 Oct 2022 08:43:11 +0200 Subject: [PATCH 11/55] fix: unit test requires dependencies in suggests (#919) --- tests/testthat/test-extra_sysreqs.R | 2 ++ tests/testthat/test-pkg_tools.R | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-extra_sysreqs.R b/tests/testthat/test-extra_sysreqs.R index 6530b095..d0e47254 100644 --- a/tests/testthat/test-extra_sysreqs.R +++ b/tests/testthat/test-extra_sysreqs.R @@ -1,3 +1,5 @@ +skip_if_not_installed("dockerfiler", minimum_version = "0.2.0") + test_that("test extra sysreqs", { skip_if_not_installed("renv") skip_if_not_installed("dockerfiler", "0.2.0") diff --git a/tests/testthat/test-pkg_tools.R b/tests/testthat/test-pkg_tools.R index d56c0a43..bc1af90a 100644 --- a/tests/testthat/test-pkg_tools.R +++ b/tests/testthat/test-pkg_tools.R @@ -1,9 +1,11 @@ +skip_if_not_installed("pkgload") + test_that("pkgtools works", { withr::with_dir(pkg, { - expect_equal(pkg_name(), fakename) - expect_equal(pkg_version(), "0.0.0.9000") + expect_equal(pkgload::pkg_name(), fakename) + expect_equal(as.character(pkgload::pkg_version()), "0.0.0.9000") # F-word windows path skip_on_os("windows") - expect_equal(pkg_path(), pkg) + expect_equal(pkgload::pkg_path(), pkg) }) }) From fccedc885174d09c8af74e38a713b1b6fcf93b82 Mon Sep 17 00:00:00 2001 From: Colin Fay Date: Fri, 14 Oct 2022 08:46:29 +0200 Subject: [PATCH 12/55] refactor: check_installed in their own files (#931) --- R/add_dockerfiles.R | 23 ++------ R/add_dockerfiles_renv.R | 21 +++---- R/boostrap_fs.R | 82 +++++++++++++++++++++++++++ R/bootstrap_attachment.R | 23 ++++++++ R/bootstrap_dockerfiler.R | 68 ++++++++++++++++++++++ R/bootstrap_pkgload.R | 37 ++++++++++++ R/bootstrap_roxygen2.R | 23 ++++++++ R/bootstrap_usethis.R | 116 ++++++++++++++++++++++++++++++++++++++ R/fs_boostrap.R | 82 --------------------------- R/modules_fn.R | 1 - R/reload.R | 5 +- R/use_utils.R | 4 -- R/usethis_bootstrap.R | 116 -------------------------------------- 13 files changed, 363 insertions(+), 238 deletions(-) create mode 100644 R/boostrap_fs.R create mode 100644 R/bootstrap_attachment.R create mode 100644 R/bootstrap_dockerfiler.R create mode 100644 R/bootstrap_pkgload.R create mode 100644 R/bootstrap_roxygen2.R create mode 100644 R/bootstrap_usethis.R delete mode 100644 R/fs_boostrap.R delete mode 100644 R/usethis_bootstrap.R diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index 490c10a1..aa48f190 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -142,11 +142,6 @@ add_dockerfile_ <- talk_once( build_golem_from_source = TRUE, extra_sysreqs = NULL ) { - rlang::check_installed( - "dockerfiler", - version = "0.2.0", - reason = "to build a Dockerfile." - ) where <- fs_path(pkg, output) @@ -154,7 +149,7 @@ add_dockerfile_ <- talk_once( basename(where) ) - dock <- dockerfiler::dock_from_desc( + dock <- dockerfiler_dock_from_desc( path = path, FROM = from, AS = as, @@ -254,16 +249,12 @@ add_dockerfile_shinyproxy_ <- talk_once( build_golem_from_source = TRUE, extra_sysreqs = NULL ) { - rlang::check_installed( - "dockerfiler", - version = "0.2.0", - reason = "to build a Dockerfile." - ) + where <- fs_path(pkg, output) usethis_use_build_ignore(output) - dock <- dockerfiler::dock_from_desc( + dock <- dockerfiler_dock_from_desc( path = path, FROM = from, AS = as, @@ -357,16 +348,12 @@ add_dockerfile_heroku_ <- talk_once( build_golem_from_source = TRUE, extra_sysreqs = NULL ) { - rlang::check_installed( - "dockerfiler", - version = "0.2.0", - reason = "to build a Dockerfile." - ) + where <- fs_path(pkg, output) usethis_use_build_ignore(output) - dock <- dockerfiler::dock_from_desc( + dock <- dockerfiler_dock_from_desc( path = path, FROM = from, AS = as, diff --git a/R/add_dockerfiles_renv.R b/R/add_dockerfiles_renv.R index 93f5d3fb..160a357b 100644 --- a/R/add_dockerfiles_renv.R +++ b/R/add_dockerfiles_renv.R @@ -16,17 +16,7 @@ add_dockerfile_with_renv_ <- function( "renv", reason = "to build a Dockerfile." ) - rlang::check_installed( - "dockerfiler", - version = "0.2.0", - reason = "to build a Dockerfile." - ) - rlang::check_installed( - "attachment", - version = "0.2.5", - reason = "to build a Dockerfile." - ) - + # Small hack to prevent warning from rlang::lang() in tests # This should be managed in {attempt} later on x <- suppressWarnings({ @@ -41,7 +31,7 @@ add_dockerfile_with_renv_ <- function( } if (is.null(lockfile)) { - lockfile <- attachment::create_renv_for_prod( + lockfile <- attachment_create_renv_for_prod( path = source_folder, output = file.path(output_dir, "renv.lock.prod") ) @@ -53,7 +43,7 @@ add_dockerfile_with_renv_ <- function( overwrite = TRUE ) - socle <- dockerfiler::dock_from_renv( + socle <- dockerfiler_dock_from_renv( lockfile = lockfile, distro = distro, FROM = FROM, @@ -66,7 +56,10 @@ add_dockerfile_with_renv_ <- function( socle$write(as = file.path(output_dir, "Dockerfile_base")) - my_dock <- dockerfiler::Dockerfile$new(FROM = paste0(golem::get_golem_name(), "_base")) + my_dock <- dockerfiler_Dockerfile()$new( + FROM = paste0(golem::get_golem_name(), + "_base" + )) my_dock$COPY("renv.lock.prod", "renv.lock") diff --git a/R/boostrap_fs.R b/R/boostrap_fs.R new file mode 100644 index 00000000..9b022bf0 --- /dev/null +++ b/R/boostrap_fs.R @@ -0,0 +1,82 @@ +# All the fns here check that {fs} is installed +# before doing anything. +check_fs_installed <- function() { + rlang::check_installed( + "fs", + reason = "for file & directory manipulation.\nYou can install all {golem} dev dependencies with `golem::install_dev_deps()`." + ) +} + +fs_dir_exists <- function(path) { + check_fs_installed() + fs::dir_exists(path) +} + +fs_dir_create <- function( + path, + ..., + mode = "u=rwx,go=rx", + recurse = TRUE, + recursive +) { + check_fs_installed() + fs::dir_create( + path, + ..., + mode = mode, + recurse = recurse, + recursive = recursive + ) +} + + +fs_file_create <- function(where) { + check_fs_installed() + fs::file_create(where) +} + +fs_file_delete <- function(path) { + check_fs_installed() + fs::file_delete(path) +} + +fs_file_exists <- function(path) { + check_fs_installed() + fs::file_exists(path) +} + +fs_path_abs <- function(path) { + check_fs_installed() + fs::path_abs(path) +} + +fs_path <- function(..., ext = "") { + check_fs_installed() + fs::path(..., ext = ext) +} + +fs_file_copy <- function( + path, + new_path, + overwrite = FALSE +) { + check_fs_installed() + fs::file_copy( + path = path, + new_path = new_path, + overwrite + ) +} + +fs_dir_copy <- function( + path, + new_path, + overwrite = FALSE +) { + check_fs_installed() + fs::dir_copy( + path, + new_path, + overwrite + ) +} diff --git a/R/bootstrap_attachment.R b/R/bootstrap_attachment.R new file mode 100644 index 00000000..08e65c16 --- /dev/null +++ b/R/bootstrap_attachment.R @@ -0,0 +1,23 @@ +# All the fns here check that {attachment} is installed +# before doing anything. +check_attachment_installed <- function() { + rlang::check_installed( + "attachment", + version = "0.2.5", + reason = "to build a Dockerfile." + ) +} + +attachment_create_renv_for_prod <- function( + path = ".", + output = "renv.lock.prod", + dev_pkg = "remotes", + ... +) { + attachment::create_renv_for_prod( + path = path, + output = output, + dev_pkg = dev_pkg, + ... + ) +} diff --git a/R/bootstrap_dockerfiler.R b/R/bootstrap_dockerfiler.R new file mode 100644 index 00000000..5dd79aad --- /dev/null +++ b/R/bootstrap_dockerfiler.R @@ -0,0 +1,68 @@ +# All the fns here check that {dockerfiler} is installed +# before doing anything. +check_dockerfiler_installed <- function() { + rlang::check_installed( + "dockerfiler", + version = "0.2.0", + reason = "to build a Dockerfile." + ) +} + +dockerfiler_dock_from_renv <- function( + lockfile = "renv.lock", + distro = "focal", + FROM = "rocker/r-base", + AS = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + extra_sysreqs = NULL +) { + check_dockerfiler_installed() + dockerfiler::dock_from_renv( + lockfile = lockfile, + distro = distro, + FROM = FROM, + AS = AS, + sysreqs = sysreqs, + repos = repos, + expand = expand, + extra_sysreqs = extra_sysreqs + ) +} + +dockerfiler_dock_from_desc <- function( + path = "DESCRIPTION", + FROM = paste0( + "rocker/r-ver:", + R.Version()$major, + ".", + R.Version()$minor + ), + AS = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + update_tar_gz = TRUE, + build_from_source = TRUE, + extra_sysreqs = NULL +) { + check_dockerfiler_installed() + dockerfiler::dock_from_desc( + path = path, + FROM = FROM, + AS = AS, + sysreqs = sysreqs, + repos = repos, + expand = expand, + update_tar_gz = update_tar_gz, + build_from_source = build_from_source, + extra_sysreqs = extra_sysreqs + ) +} + + +dockerfiler_Dockerfile <- function() { + check_dockerfiler_installed() + dockerfiler::Dockerfile +} diff --git a/R/bootstrap_pkgload.R b/R/bootstrap_pkgload.R new file mode 100644 index 00000000..b4db04cc --- /dev/null +++ b/R/bootstrap_pkgload.R @@ -0,0 +1,37 @@ +# All the fns here check that {pkgload} is installed +# before doing anything. +check_pkgload_installed <- function() { + rlang::check_installed( + "pkgload", + reason = "to load the package." + ) +} + +pkgload_load_all <- function( + path = ".", + reset = TRUE, + compile = NA, + attach = TRUE, + export_all = TRUE, + export_imports = export_all, + helpers = TRUE, + attach_testthat = uses_testthat(path), + quiet = NULL, + recompile = FALSE, + warn_conflicts = TRUE +) { + check_roxygen2_installed() + pkgload::load_all( + path = path, + reset = reset, + compile = compile, + attach = attach, + export_all = export_all, + export_imports = export_imports, + helpers = helpers, + attach_testthat = attach_testthat, + quiet = quiet, + recompile = recompile, + warn_conflicts = warn_conflicts + ) +} diff --git a/R/bootstrap_roxygen2.R b/R/bootstrap_roxygen2.R new file mode 100644 index 00000000..e836517c --- /dev/null +++ b/R/bootstrap_roxygen2.R @@ -0,0 +1,23 @@ +# All the fns here check that {roxygen2} is installed +# before doing anything. +check_roxygen2_installed <- function() { + rlang::check_installed( + "roxygen2", + reason = "to document the package." + ) +} + +roxygen2_roxygenise <- function( + package.dir = ".", + roclets = NULL, + load_code = NULL, + clean = FALSE +) { + check_roxygen2_installed() + roxygen2::roxygenise( + package.dir = package.dir, + roclets = roclets, + load_code = load_code, + clean = clean + ) +} diff --git a/R/bootstrap_usethis.R b/R/bootstrap_usethis.R new file mode 100644 index 00000000..a153d78b --- /dev/null +++ b/R/bootstrap_usethis.R @@ -0,0 +1,116 @@ + +# All the fns here check that {usethis} is installed +# before doing anything. +check_usethis_installed <- function(reason = "for project and file manipulation.") { + rlang::check_installed( + "usethis", + version = "1.6.0", + reason = reason + ) +} + +usethis_use_build_ignore <- function( + files, + escape = TRUE +) { + check_usethis_installed( + reason = "to ignore files in the build." + ) + usethis::use_build_ignore( + files, + escape + ) +} +usethis_use_package <- function( + package, + type = "Imports", + min_version = NULL +) { + check_usethis_installed( + reason = "to add dependencies to DESCRIPTION." + ) + usethis::use_package( + package, + type, + min_version + ) +} + +usethis_create_project <- function( + path, + rstudio = rstudioapi::isAvailable(), + open = rlang::is_interactive() +) { + check_usethis_installed( + reason = "to create a project." + ) + usethis::create_project( + path, + rstudio, + open + ) +} +usethis_use_latest_dependencies <- function( + overwrite = FALSE, + source = c("local", "CRAN") +) { + check_usethis_installed( + reason = "to set dependency version." + ) + usethis::use_latest_dependencies( + overwrite, + source + ) +} + +usethis_proj_set <- function( + path = ".", + force = FALSE +) { + check_usethis_installed( + reason = "to set project." + ) + usethis::proj_set( + path, + force + ) +} +usethis_use_testthat <- function( + edition = NULL, + parallel = FALSE +) { + check_usethis_installed( + reason = "to add {testthat} infrastructure." + ) + usethis::use_testthat( + edition, + parallel + ) +} +usethis_use_test <- function( + name = NULL, + open = rlang::is_interactive() +) { + check_usethis_installed( + reason = "to add tests." + ) + usethis::use_test( + name, + open + ) +} + +usethis_use_spell_check <- function( + vignettes = TRUE, + lang = "en-US", + error = FALSE +) { + check_usethis_installed( + reason = "to add spellcheck." + ) + usethis::use_spell_check( + vignettes, + lang, + error + ) +} diff --git a/R/fs_boostrap.R b/R/fs_boostrap.R deleted file mode 100644 index 55ab5b83..00000000 --- a/R/fs_boostrap.R +++ /dev/null @@ -1,82 +0,0 @@ -# All the fns here check that {fs} is installed -# before doing anything. -check_fs_installed <- function() { - rlang::check_installed( - "fs", - reason = "for file & directory manipulation.\nYou can install all {golem} dev dependencies with `golem::install_dev_deps()`." - ) -} - -fs_dir_exists <- function(path) { - check_fs_installed() - fs::dir_exists(path) -} - -fs_dir_create <- function( - path, - ..., - mode = "u=rwx,go=rx", - recurse = TRUE, - recursive -) { - check_fs_installed() - fs::dir_create( - path, - ..., - mode = mode, - recurse = recurse, - recursive = recursive - ) -} - - -fs_file_create <- function(where) { - check_fs_installed() - fs::file_create(where) -} - -fs_file_delete <- function(path) { - check_fs_installed() - fs::file_delete(path) -} - -fs_file_exists <- function(path) { - check_fs_installed() - fs::file_exists(path) -} - -fs_path_abs <- function(path) { - check_fs_installed() - fs::path_abs(path) -} - -fs_path <- function(..., ext = "") { - check_fs_installed() - fs::path(..., ext = ext) -} - -fs_file_copy <- function( - path, - new_path, - overwrite = FALSE -) { - check_fs_installed() - fs::file_copy( - path = path, - new_path = new_path, - overwrite - ) -} - -fs_dir_copy <- function( - path, - new_path, - overwrite = FALSE -) { - check_fs_installed() - fs::dir_copy( - path, - new_path, - overwrite - ) -} diff --git a/R/modules_fn.R b/R/modules_fn.R index c871b6cf..864c666e 100644 --- a/R/modules_fn.R +++ b/R/modules_fn.R @@ -257,7 +257,6 @@ use_module_test <- function( # We need both testthat, usethis & fs check_is_installed("testthat") - check_is_installed("fs") old <- setwd(fs_path_abs(pkg)) on.exit(setwd(old)) diff --git a/R/reload.R b/R/reload.R index b124da96..3f16d7f4 100644 --- a/R/reload.R +++ b/R/reload.R @@ -106,13 +106,12 @@ document_and_reload <- function( check_name_consistency(pkg) rlang::check_installed("pkgload") - rlang::check_installed("roxygen2") if (rstudioapi::isAvailable() & rstudioapi::hasFun("documentSaveAll")) { rstudioapi::documentSaveAll() } roxed <- try({ - roxygen2::roxygenise( + roxygen2_roxygenise( package.dir = pkg, roclets = roclets, load_code = load_code, @@ -127,7 +126,7 @@ document_and_reload <- function( return(invisible(FALSE)) } loaded <- try({ - pkgload::load_all( + pkgload_load_all( pkg, export_all = export_all, helpers = helpers, diff --git a/R/use_utils.R b/R/use_utils.R index ef2c1f46..ebe09768 100644 --- a/R/use_utils.R +++ b/R/use_utils.R @@ -135,10 +135,6 @@ use_utils <- function( folder_name, pkg = get_golem_wd() ) { - rlang::check_installed( - "fs", - reason = "for file manipulation." - ) old <- setwd( fs_path_abs(pkg) diff --git a/R/usethis_bootstrap.R b/R/usethis_bootstrap.R deleted file mode 100644 index 1e513da5..00000000 --- a/R/usethis_bootstrap.R +++ /dev/null @@ -1,116 +0,0 @@ - -# All the fns here check that {usethis} is installed -# before doing anything. -check_usethis_installed <- function(reason = "for project and file manipulation.") { - rlang::check_installed( - "usethis", - version = "1.6.0", - reason = reason - ) -} - -usethis_use_build_ignore <- function( - files, - escape = TRUE -) { - check_usethis_installed( - reason = "to ignore files in the build." - ) - usethis::use_build_ignore( - files, - escape - ) -} -usethis_use_package <- function( - package, - type = "Imports", - min_version = NULL -) { - check_usethis_installed( - reason = "to add dependencies to DESCRIPTION." - ) - usethis::use_package( - package, - type, - min_version - ) -} - -usethis_create_project <- function( - path, - rstudio = rstudioapi::isAvailable(), - open = rlang::is_interactive() -) { - check_usethis_installed( - reason = "to create a project." - ) - usethis::create_project( - path, - rstudio, - open - ) -} -usethis_use_latest_dependencies <- function( - overwrite = FALSE, - source = c("local", "CRAN") -) { - check_usethis_installed( - reason = "to set dependency version." - ) - usethis::use_latest_dependencies( - overwrite, - source - ) -} - -usethis_proj_set <- function( - path = ".", - force = FALSE -) { - check_usethis_installed( - reason = "to set project." - ) - usethis::proj_set( - path, - force - ) -} -usethis_use_testthat <- function( - edition = NULL, - parallel = FALSE -) { - check_usethis_installed( - reason = "to add {testthat} infrastructure." - ) - usethis::use_testthat( - edition, - parallel - ) -} -usethis_use_test <- function( - name = NULL, - open = rlang::is_interactive() -) { - check_usethis_installed( - reason = "to add tests." - ) - usethis::use_test( - name, - open - ) -} - -usethis_use_spell_check <- function( - vignettes = TRUE, - lang = "en-US", - error = FALSE -) { - check_usethis_installed( - reason = "to add spellcheck." - ) - usethis::use_spell_check( - vignettes, - lang, - error - ) -} From beeda815ab49a64743d62cb59adfeede205a1997 Mon Sep 17 00:00:00 2001 From: Colin Fay Date: Fri, 14 Oct 2022 19:56:19 +0200 Subject: [PATCH 13/55] feat: Make cat functions conditional to an options (#934) --- R/add_files.R | 2 +- R/bootstrap_pkgload.R | 3 + R/create_golem.R | 4 +- R/disable_autoload.R | 2 +- R/reload.R | 4 +- R/set_golem_options.R | 4 +- R/utils.R | 100 +++++++++++++++++------ tests/testthat/helper-config.R | 4 +- tests/testthat/test-add_deploy_helpers.R | 62 ++++++++------ tests/testthat/test-add_modules.R | 5 +- tests/testthat/test-desc.R | 23 +++--- tests/testthat/test-extra_sysreqs.R | 6 +- tests/testthat/test-make_dev.R | 5 +- tests/testthat/test-test_helpers.R | 14 +++- 14 files changed, 160 insertions(+), 78 deletions(-) diff --git a/R/add_files.R b/R/add_files.R index 08a420ea..1b964d21 100644 --- a/R/add_files.R +++ b/R/add_files.R @@ -512,7 +512,7 @@ add_sass_file <- function( name = name ) - cli_alert_info( + cat_green_tick( "After running the compilation, your CSS file will be automatically link in `golem_add_external_resources()`." ) } else { diff --git a/R/bootstrap_pkgload.R b/R/bootstrap_pkgload.R index b4db04cc..3c90630a 100644 --- a/R/bootstrap_pkgload.R +++ b/R/bootstrap_pkgload.R @@ -7,6 +7,9 @@ check_pkgload_installed <- function() { ) } +uses_testthat <- getFromNamespace( "uses_testthat", "pkgload" ) + + pkgload_load_all <- function( path = ".", reset = TRUE, diff --git a/R/create_golem.R b/R/create_golem.R index 12bc8db6..fb77355f 100644 --- a/R/create_golem.R +++ b/R/create_golem.R @@ -113,7 +113,9 @@ create_golem <- function( path = path_to_golem, open = FALSE ) - here::set_here(path_to_golem) + if (!file.exists(".here")){ + here::set_here(path_to_golem) + } cat_green_tick("Created package directory") } diff --git a/R/disable_autoload.R b/R/disable_autoload.R index 64215656..a984b02c 100644 --- a/R/disable_autoload.R +++ b/R/disable_autoload.R @@ -20,7 +20,7 @@ disable_autoload <- function(pkg = get_golem_wd()) { "_disable_autoload.R already exists, skipping its creation." ) } else { - cli::cat_rule("Creating _disable_autoload.R") + cat_rule("Creating _disable_autoload.R") write( "# Disabling shiny autoload\n\n# See ?shiny::loadSupport for more information", fls diff --git a/R/reload.R b/R/reload.R index 3f16d7f4..2bb9e51f 100644 --- a/R/reload.R +++ b/R/reload.R @@ -119,7 +119,7 @@ document_and_reload <- function( ) }) if (attempt::is_try_error(roxed)) { - cli::cat_rule( + cat_rule( "Error documenting your package" ) dialog_if_has("Alert", "Error documenting your package") @@ -136,7 +136,7 @@ document_and_reload <- function( }) if (attempt::is_try_error(loaded)) { - cli::cat_rule( + cat_rule( "Error loading your package" ) dialog_if_has("Alert", "Error loading your package") diff --git a/R/set_golem_options.R b/R/set_golem_options.R index 28ddd90c..2a965ae9 100644 --- a/R/set_golem_options.R +++ b/R/set_golem_options.R @@ -48,7 +48,7 @@ set_golem_options <- function( # golem_install_dev_pkg() function if (talkative) { - cli::cat_rule( + cat_rule( "Setting {golem} options in `golem-config.yml`" ) } @@ -90,7 +90,7 @@ set_golem_options <- function( # This part is for {usethis} and {here} if (talkative) { - cli::cat_rule( + cat_rule( "Setting {usethis} project as `golem_wd`" ) } diff --git a/R/utils.R b/R/utils.R index 2246d5ea..f6498796 100644 --- a/R/utils.R +++ b/R/utils.R @@ -113,29 +113,55 @@ remove_comments <- function(file) { #' @importFrom cli cat_bullet cat_green_tick <- function(...) { - cat_bullet( - ..., - bullet = "tick", - bullet_col = "green" - ) + do_if_unquiet({ + cat_bullet( + ..., + bullet = "tick", + bullet_col = "green" + ) + }) } #' @importFrom cli cat_bullet cat_red_bullet <- function(...) { - cat_bullet( - ..., - bullet = "bullet", - bullet_col = "red" - ) + do_if_unquiet({ + cli::cat_bullet( + ..., + bullet = "bullet", + bullet_col = "red" + ) + }) } #' @importFrom cli cat_bullet cat_info <- function(...) { - cat_bullet( - ..., - bullet = "arrow_right", - bullet_col = "grey" - ) + do_if_unquiet({ + cli::cat_bullet( + ..., + bullet = "arrow_right", + bullet_col = "grey" + ) + }) +} + +cat_rule <- function( + ... +) { + do_if_unquiet({ + cli::cat_rule( + ... + ) + }) +} + +cat_line <- function( + ... +) { + do_if_unquiet({ + cli::cat_line( + ... + ) + }) } cat_exists <- function(where) { @@ -160,8 +186,10 @@ cat_dir_necessary <- function() { } cat_start_download <- function() { - cat_line("") - cat_rule("Initiating file download") + do_if_unquiet({ + cat_line("") + cat_rule("Initiating file download") + }) } cat_downloaded <- function( @@ -178,8 +206,10 @@ cat_downloaded <- function( } cat_start_copy <- function() { - cat_line("") - cat_rule("Copying file") + do_if_unquiet({ + cat_line("") + cat_rule("Copying file") + }) } cat_copied <- function( @@ -314,13 +344,15 @@ after_creation_message_html_template <- function( dir, name ) { - cat_line("") - cat_rule("To use this html file as a template, add the following code in your UI:") - cat_line(darkgrey("htmlTemplate(")) - cat_line(darkgrey(sprintf(' app_sys("app/www/%s.html"),', file_path_sans_ext(name)))) - cat_line(darkgrey(" body = tagList()")) - cat_line(darkgrey(" # add here other template arguments")) - cat_line(darkgrey(")")) + do_if_unquiet({ + cat_line("") + cat_rule("To use this html file as a template, add the following code in your UI:") + cat_line(darkgrey("htmlTemplate(")) + cat_line(darkgrey(sprintf(' app_sys("app/www/%s.html"),', file_path_sans_ext(name)))) + cat_line(darkgrey(" body = tagList()")) + cat_line(darkgrey(" # add here other template arguments")) + cat_line(darkgrey(")")) + }) } file_created_dance <- function( @@ -447,3 +479,19 @@ check_name_length <- function(name) { ) ) } + +do_if_unquiet <- function( + expr +){ + if( + ! getOption( + "golem.quiet", + getOption( + "usethis.quiet", + default = FALSE + ) + ) + ){ + force(expr) + } +} \ No newline at end of file diff --git a/tests/testthat/helper-config.R b/tests/testthat/helper-config.R index 52f85e55..f50b9073 100644 --- a/tests/testthat/helper-config.R +++ b/tests/testthat/helper-config.R @@ -81,7 +81,9 @@ rand_name <- function() { withr::with_dir(pkg, { # Some weird things with {here} unloadNamespace("here") - here::set_here(".") + if (!file.exists(".here")){ + here::set_here(path_to_golem) + } set_golem_options() usethis::proj_set(pkg) orig_test <- set_golem_wd( diff --git a/tests/testthat/test-add_deploy_helpers.R b/tests/testthat/test-add_deploy_helpers.R index b798603f..0bbe2181 100644 --- a/tests/testthat/test-add_deploy_helpers.R +++ b/tests/testthat/test-add_deploy_helpers.R @@ -12,9 +12,14 @@ test_that("add_dockerfiles", { burn_after_reading( "Dockerfile", { - output <- testthat::capture_output( - fun(pkg = pkg, sysreqs = FALSE, open = FALSE) + withr::with_options( + c("golem.quiet" = FALSE),{ + output <- testthat::capture_output( + fun(pkg = pkg, sysreqs = FALSE, open = FALSE) + ) + } ) + expect_exists("Dockerfile") test <- stringr::str_detect( output, @@ -37,27 +42,29 @@ test_that("add_dockerfiles repos variation", { burn_after_reading( c("Dockerfile1", "Dockerfile2"), { - output1 <- testthat::capture_output( - fun( - pkg = pkg, - sysreqs = FALSE, - open = FALSE, - repos = "https://cran.rstudio.com/", - output = "Dockerfile1" + withr::with_options( + c("golem.quiet" = FALSE),{ + output1 <- testthat::capture_output( + fun( + pkg = pkg, + sysreqs = FALSE, + open = FALSE, + repos = "https://cran.rstudio.com/", + output = "Dockerfile1" + ) ) - ) - output2 <- testthat::capture_output( - fun( - pkg = pkg, - sysreqs = FALSE, - open = FALSE, - repos = c("https://cran.rstudio.com/"), - output = "Dockerfile2" + output2 <- testthat::capture_output( + fun( + pkg = pkg, + sysreqs = FALSE, + open = FALSE, + repos = c("https://cran.rstudio.com/"), + output = "Dockerfile2" + ) ) - ) - expect_exists("Dockerfile1") - expect_exists("Dockerfile2") - + expect_exists("Dockerfile1") + expect_exists("Dockerfile2") + }) test1 <- stringr::str_detect( output1, @@ -91,12 +98,15 @@ test_that("add_rstudio_files", { burn_after_reading( "app.R", { - output <- testthat::capture_output( - fun( - pkg = pkg, - open = FALSE - ) + withr::with_options( + c("golem.quiet" = FALSE),{ + output <- testthat::capture_output( + fun( + pkg = pkg, + open = FALSE + ) ) + }) expect_exists("app.R") test <- stringr::str_detect( output, diff --git a/tests/testthat/test-add_modules.R b/tests/testthat/test-add_modules.R index a1584aef..af70b65b 100644 --- a/tests/testthat/test-add_modules.R +++ b/tests/testthat/test-add_modules.R @@ -15,7 +15,10 @@ test_that("add_module", { lapply(tools::file_ext(script), function(x) testthat::expect_equal(x, "R")) ## Test message of function remove_file("R/mod_output.R") - output <- testthat::capture_output(add_module("output", open = FALSE)) + withr::with_options( + c("golem.quiet" = FALSE),{ + output <- testthat::capture_output(add_module("output", open = FALSE)) + }) expect_true( stringr::str_detect(output, "File created at R/mod_output.R") ) diff --git a/tests/testthat/test-desc.R b/tests/testthat/test-desc.R index 7af2b91f..86ec958b 100644 --- a/tests/testthat/test-desc.R +++ b/tests/testthat/test-desc.R @@ -1,17 +1,20 @@ test_that("desc works", { with_dir(pkg, { - output <- capture_output( - fill_desc( - fakename, - "newtitle", - "Newdescription.", - "firstname", - "lastname", - "name@test.com", - "http://repo_url.com" + withr::with_options( + c("golem.quiet" = FALSE),{ + output <- capture_output( + fill_desc( + fakename, + "newtitle", + "Newdescription.", + "firstname", + "lastname", + "name@test.com", + "http://repo_url.com" + ) ) - ) + }) add_desc <- c( fakename, "newtitle", diff --git a/tests/testthat/test-extra_sysreqs.R b/tests/testthat/test-extra_sysreqs.R index d0e47254..286f0999 100644 --- a/tests/testthat/test-extra_sysreqs.R +++ b/tests/testthat/test-extra_sysreqs.R @@ -13,7 +13,9 @@ test_that("test extra sysreqs", { burn_after_reading( "Dockerfile", { - output <- testthat::capture_output( + withr::with_options( + c("golem.quiet" = FALSE),{ + output <- testthat::capture_output( fun( pkg = pkg, sysreqs = FALSE, @@ -22,7 +24,7 @@ test_that("test extra sysreqs", { output = "Dockerfile" ) ) - + }) expect_exists("Dockerfile") test <- stringr::str_detect( output, diff --git a/tests/testthat/test-make_dev.R b/tests/testthat/test-make_dev.R index bbf46547..5f736b7a 100644 --- a/tests/testthat/test-make_dev.R +++ b/tests/testthat/test-make_dev.R @@ -60,7 +60,10 @@ test_that("test print_dev", { test_that("test browser_button", { - output <- capture_output_lines(browser_button()) + withr::with_options( + c("golem.quiet" = FALSE),{ + output <- capture_output_lines(browser_button()) + }) expect_true( grepl('actionButton\\("browser", "browser"\\)', output[2]) ) diff --git a/tests/testthat/test-test_helpers.R b/tests/testthat/test-test_helpers.R index c1e4ccad..82aa04c2 100644 --- a/tests/testthat/test-test_helpers.R +++ b/tests/testthat/test-test_helpers.R @@ -1,13 +1,19 @@ test_that("test expect_shinytag", { with_dir(pkg, { - expect_equal(capture_output(expect_shinytag(favicon("jean"))), "") - expect_error(expect_shinytag("pierre")) + withr::with_options( + c("golem.quiet" = FALSE),{ + expect_equal(capture_output(expect_shinytag(favicon("jean"))), "") + expect_error(expect_shinytag("pierre")) + }) }) }) test_that("test expect_shinytaglist", { with_dir(pkg, { - expect_equal(capture_output(expect_shinytaglist(shiny::tagList())), "") - expect_error(expect_shinytaglist("test")) + withr::with_options( + c("golem.quiet" = FALSE),{ + expect_equal(capture_output(expect_shinytaglist(shiny::tagList())), "") + expect_error(expect_shinytaglist("test")) + }) }) }) From a1f80f5f8a5ed1d7c25816d609afba3a8ccadd77 Mon Sep 17 00:00:00 2001 From: Antoine Languillaume <43757522+ALanguillaume@users.noreply.github.com> Date: Thu, 27 Oct 2022 11:26:37 +0200 Subject: [PATCH 14/55] doc: improve documentation of dockerfile related functions (#939) --- R/add_dockerfiles.R | 9 ++++++--- man/dockerfiles.Rd | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index 0cf7ea6e..3ff28048 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -11,8 +11,10 @@ talk_once <- function(.f, msg = "") { #' Create a Dockerfile for your App #' -#' Build a container containing your Shiny App. `add_dockerfile()` and `add_dockerfile_with_renv()` and `add_dockerfile_with_renv()` creates -#' a generic Dockerfile, while `add_dockerfile_shinyproxy()`, `add_dockerfile_with_renv_shinyproxy()` , `add_dockerfile_with_renv_shinyproxy()` and +#' Build a container containing your Shiny App. `add_dockerfile()` and +#' `add_dockerfile_with_renv()` and `add_dockerfile_with_renv()` creates +#' a generic Dockerfile, while `add_dockerfile_shinyproxy()`, +#' `add_dockerfile_with_renv_shinyproxy()` , `add_dockerfile_with_renv_shinyproxy()` and #' `add_dockerfile_heroku()` creates platform specific Dockerfile. #' #' @inheritParams add_module @@ -31,7 +33,8 @@ talk_once <- function(.f, msg = "") { #' Default is 80. #' @param host The `options('shiny.host')` on which to run the App. #' Default is 0.0.0.0. -#' @param sysreqs boolean. If TRUE, the Dockerfile will contain sysreq installation. +#' @param sysreqs boolean. If TRUE, RUN statements to install packages +#' system requirements will be included in the Dockerfile. #' @param repos character. The URL(s) of the repositories to use for `options("repos")`. #' @param expand boolean. If `TRUE` each system requirement will have its own `RUN` line. #' @param open boolean. Should the Dockerfile/README/README be open after creation? Default is `TRUE`. diff --git a/man/dockerfiles.Rd b/man/dockerfiles.Rd index a8a7738e..6a54e1a0 100644 --- a/man/dockerfiles.Rd +++ b/man/dockerfiles.Rd @@ -127,7 +127,8 @@ Default is 80.} \item{host}{The \code{options('shiny.host')} on which to run the App. Default is 0.0.0.0.} -\item{sysreqs}{boolean. If TRUE, the Dockerfile will contain sysreq installation.} +\item{sysreqs}{boolean. If TRUE, RUN statements to install packages +system requirements will be included in the Dockerfile.} \item{repos}{character. The URL(s) of the repositories to use for \code{options("repos")}.} @@ -160,8 +161,10 @@ the CMD will be \verb{R -e "options('shiny.port'=\{port\},shiny.host='\{host\}') The \code{{dockerfiler}} object, invisibly. } \description{ -Build a container containing your Shiny App. \code{add_dockerfile()} and \code{add_dockerfile_with_renv()} and \code{add_dockerfile_with_renv()} creates -a generic Dockerfile, while \code{add_dockerfile_shinyproxy()}, \code{add_dockerfile_with_renv_shinyproxy()} , \code{add_dockerfile_with_renv_shinyproxy()} and +Build a container containing your Shiny App. \code{add_dockerfile()} and +\code{add_dockerfile_with_renv()} and \code{add_dockerfile_with_renv()} creates +a generic Dockerfile, while \code{add_dockerfile_shinyproxy()}, +\code{add_dockerfile_with_renv_shinyproxy()} , \code{add_dockerfile_with_renv_shinyproxy()} and \code{add_dockerfile_heroku()} creates platform specific Dockerfile. } \examples{ From 5c4d10e7ee01492a76d578c66931f6e72937136f Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 27 Oct 2022 11:29:34 +0200 Subject: [PATCH 15/55] chore: version bump & news update --- DESCRIPTION | 2 +- NEWS.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f8af5849..5ec8d78d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: golem Title: A Framework for Robust Shiny Applications -Version: 0.3.5.9001 +Version: 0.3.5.9002 Authors@R: c(person(given = "Colin", family = "Fay", diff --git a/NEWS.md b/NEWS.md index 7591fb56..8cf9bb2f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -17,6 +17,7 @@ + `golem::run_dev()` has been refactored to match the behavior of other functions, notably it now uses `golem::get_golem_wd()` to find the current working dir. + `{golem}` now depends on `{rlang}` version >= 1.0.0 + Functions that print to the console are now quiet if `options("golem.quiet" = TRUE)`, #793 ++ Small documentation update in dockerfile related functions (#939) ## Bug fix From 842d0c32c82d558dd321af00486234d7944a1e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Br=C3=A9ant?= <35060481+ArthurData@users.noreply.github.com> Date: Thu, 27 Oct 2022 11:59:10 +0200 Subject: [PATCH 16/55] feat: fill_desc allows to set package version (#941) --- R/desc.R | 6 ++++-- inst/mantests/build.R | 3 ++- inst/shinyexample/dev/01_start.R | 3 ++- man/fill_desc.Rd | 3 +++ tests/testthat/test-desc.R | 18 ++++++++++-------- vignettes/a_start.Rmd | 3 ++- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/R/desc.R b/R/desc.R index 45bb25fd..ffb68d8a 100644 --- a/R/desc.R +++ b/R/desc.R @@ -8,6 +8,7 @@ #' @param author_email Email of the author #' @param author_orcid ORCID of the author #' @param repo_url URL (if needed) +#' @param pkg_version The version of the package. Default is 0.0.0.9000 #' @param pkg Path to look for the DESCRIPTION. Default is `get_golem_wd()`. #' #' @importFrom desc description @@ -25,6 +26,7 @@ fill_desc <- function( author_email, author_orcid = NULL, repo_url = NULL, + pkg_version = "0.0.0.9000", pkg = get_golem_wd() ) { path <- fs_path_abs(pkg) @@ -64,10 +66,10 @@ fill_desc <- function( keys = "Maintainer" ) desc$set_version( - version = "0.0.0.9000" + version = pkg_version ) set_golem_version( - version = "0.0.0.9000", + version = pkg_version, pkg = path ) desc$set( diff --git a/inst/mantests/build.R b/inst/mantests/build.R index 1f7cde70..0cc9aa44 100644 --- a/inst/mantests/build.R +++ b/inst/mantests/build.R @@ -204,7 +204,8 @@ withr::with_tempdir({ author_first_name = "Colin", # Your First Name author_last_name = "Fay", # Your Last Name author_email = "colin@thinkr.fr", # Your Email - repo_url = NULL # The URL of the GitHub Repo (optional) + repo_url = NULL, # The URL of the GitHub Repo (optional) + pkg_version = "0.0.0.9000" # The Version of the package containing the App ) cli::cat_rule("checking package name") diff --git a/inst/shinyexample/dev/01_start.R b/inst/shinyexample/dev/01_start.R index 5ea36dc4..24eee49e 100644 --- a/inst/shinyexample/dev/01_start.R +++ b/inst/shinyexample/dev/01_start.R @@ -25,7 +25,8 @@ golem::fill_desc( author_first_name = "AUTHOR_FIRST", # Your First Name author_last_name = "AUTHOR_LAST", # Your Last Name author_email = "AUTHOR@MAIL.COM", # Your Email - repo_url = NULL # The URL of the GitHub Repo (optional) + repo_url = NULL, # The URL of the GitHub Repo (optional), + pkg_version = "0.0.0.9000" # The Version of the package containing the App ) ## Set {golem} options ---- diff --git a/man/fill_desc.Rd b/man/fill_desc.Rd index 87c4885a..a851ae08 100644 --- a/man/fill_desc.Rd +++ b/man/fill_desc.Rd @@ -13,6 +13,7 @@ fill_desc( author_email, author_orcid = NULL, repo_url = NULL, + pkg_version = "0.0.0.9000", pkg = get_golem_wd() ) } @@ -33,6 +34,8 @@ fill_desc( \item{repo_url}{URL (if needed)} +\item{pkg_version}{The version of the package. Default is 0.0.0.9000} + \item{pkg}{Path to look for the DESCRIPTION. Default is \code{get_golem_wd()}.} } \value{ diff --git a/tests/testthat/test-desc.R b/tests/testthat/test-desc.R index 86ec958b..e147f82e 100644 --- a/tests/testthat/test-desc.R +++ b/tests/testthat/test-desc.R @@ -5,13 +5,14 @@ test_that("desc works", { c("golem.quiet" = FALSE),{ output <- capture_output( fill_desc( - fakename, - "newtitle", - "Newdescription.", - "firstname", - "lastname", - "name@test.com", - "http://repo_url.com" + pkg_name = fakename, + pkg_title = "newtitle", + pkg_description = "Newdescription.", + author_first_name = "firstname", + author_last_name = "lastname", + author_email = "name@test.com", + repo_url = "http://repo_url.com", + pkg_version = "0.0.0.9000" ) ) }) @@ -22,7 +23,8 @@ test_that("desc works", { "firstname", "lastname", "name@test.com", - "http://repo_url.com" + "http://repo_url.com", + "0.0.0.9000" ) desc <- readLines("DESCRIPTION") diff --git a/vignettes/a_start.Rmd b/vignettes/a_start.Rmd index 18e474e0..0dd31ef2 100644 --- a/vignettes/a_start.Rmd +++ b/vignettes/a_start.Rmd @@ -119,7 +119,8 @@ golem::fill_desc( author_first_name = "AUTHOR_FIRST", # Your First Name author_last_name = "AUTHOR_LAST", # Your Last Name author_email = "AUTHOR@MAIL.COM", # Your Email - repo_url = NULL # The (optional) URL of the GitHub Repo + repo_url = NULL, # The (optional) URL of the GitHub Repo + pkg_version = "0.0.0.9000" # The Version of the package containing the App ) ``` From 38df42cf84a6b24f982c5f9170b6075764e53ddb Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 27 Oct 2022 12:00:27 +0200 Subject: [PATCH 17/55] chore: version bump & news update --- DESCRIPTION | 2 +- NEWS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5ec8d78d..b0011c5d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: golem Title: A Framework for Robust Shiny Applications -Version: 0.3.5.9002 +Version: 0.3.5.9003 Authors@R: c(person(given = "Colin", family = "Fay", diff --git a/NEWS.md b/NEWS.md index 8cf9bb2f..d9ccf69c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,7 +18,7 @@ + `{golem}` now depends on `{rlang}` version >= 1.0.0 + Functions that print to the console are now quiet if `options("golem.quiet" = TRUE)`, #793 + Small documentation update in dockerfile related functions (#939) - ++ `fill_desc()` now allows to set the version (#877) ## Bug fix + The message after htmlTemplate creation now suggests to add in the UI, not only in app_ui.R (#861) From a75e828f13814c547a57600cafd4154aa3ebdca7 Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 27 Oct 2022 12:11:35 +0200 Subject: [PATCH 18/55] style: styler changes --- R/add_dockerfiles.R | 3 - R/add_dockerfiles_renv.R | 10 +- R/boostrap_fs.R | 94 ++++++------- R/bootstrap_attachment.R | 30 ++-- R/bootstrap_dockerfiler.R | 104 +++++++------- R/bootstrap_pkgload.R | 60 ++++---- R/bootstrap_roxygen2.R | 30 ++-- R/bootstrap_usethis.R | 166 +++++++++++------------ R/create_golem.R | 2 +- R/modules_fn.R | 2 +- R/use_utils.R | 1 - R/utils.R | 36 ++--- tests/testthat/helper-config.R | 2 +- tests/testthat/test-add_deploy_helpers.R | 63 +++++---- tests/testthat/test-add_modules.R | 8 +- tests/testthat/test-desc.R | 8 +- tests/testthat/test-extra_sysreqs.R | 24 ++-- tests/testthat/test-make_dev.R | 8 +- tests/testthat/test-test_helpers.R | 12 +- 19 files changed, 336 insertions(+), 327 deletions(-) diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index 3ff28048..323eae56 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -145,7 +145,6 @@ add_dockerfile_ <- talk_once( build_golem_from_source = TRUE, extra_sysreqs = NULL ) { - where <- fs_path(pkg, output) usethis_use_build_ignore( @@ -252,7 +251,6 @@ add_dockerfile_shinyproxy_ <- talk_once( build_golem_from_source = TRUE, extra_sysreqs = NULL ) { - where <- fs_path(pkg, output) usethis_use_build_ignore(output) @@ -351,7 +349,6 @@ add_dockerfile_heroku_ <- talk_once( build_golem_from_source = TRUE, extra_sysreqs = NULL ) { - where <- fs_path(pkg, output) usethis_use_build_ignore(output) diff --git a/R/add_dockerfiles_renv.R b/R/add_dockerfiles_renv.R index 160a357b..bed36cfa 100644 --- a/R/add_dockerfiles_renv.R +++ b/R/add_dockerfiles_renv.R @@ -16,7 +16,7 @@ add_dockerfile_with_renv_ <- function( "renv", reason = "to build a Dockerfile." ) - + # Small hack to prevent warning from rlang::lang() in tests # This should be managed in {attempt} later on x <- suppressWarnings({ @@ -57,9 +57,11 @@ add_dockerfile_with_renv_ <- function( socle$write(as = file.path(output_dir, "Dockerfile_base")) my_dock <- dockerfiler_Dockerfile()$new( - FROM = paste0(golem::get_golem_name(), - "_base" - )) + FROM = paste0( + golem::get_golem_name(), + "_base" + ) + ) my_dock$COPY("renv.lock.prod", "renv.lock") diff --git a/R/boostrap_fs.R b/R/boostrap_fs.R index 9b022bf0..55ab5b83 100644 --- a/R/boostrap_fs.R +++ b/R/boostrap_fs.R @@ -1,82 +1,82 @@ # All the fns here check that {fs} is installed # before doing anything. check_fs_installed <- function() { - rlang::check_installed( - "fs", - reason = "for file & directory manipulation.\nYou can install all {golem} dev dependencies with `golem::install_dev_deps()`." - ) + rlang::check_installed( + "fs", + reason = "for file & directory manipulation.\nYou can install all {golem} dev dependencies with `golem::install_dev_deps()`." + ) } fs_dir_exists <- function(path) { - check_fs_installed() - fs::dir_exists(path) + check_fs_installed() + fs::dir_exists(path) } fs_dir_create <- function( - path, - ..., - mode = "u=rwx,go=rx", - recurse = TRUE, - recursive + path, + ..., + mode = "u=rwx,go=rx", + recurse = TRUE, + recursive ) { - check_fs_installed() - fs::dir_create( - path, - ..., - mode = mode, - recurse = recurse, - recursive = recursive - ) + check_fs_installed() + fs::dir_create( + path, + ..., + mode = mode, + recurse = recurse, + recursive = recursive + ) } fs_file_create <- function(where) { - check_fs_installed() - fs::file_create(where) + check_fs_installed() + fs::file_create(where) } fs_file_delete <- function(path) { - check_fs_installed() - fs::file_delete(path) + check_fs_installed() + fs::file_delete(path) } fs_file_exists <- function(path) { - check_fs_installed() - fs::file_exists(path) + check_fs_installed() + fs::file_exists(path) } fs_path_abs <- function(path) { - check_fs_installed() - fs::path_abs(path) + check_fs_installed() + fs::path_abs(path) } fs_path <- function(..., ext = "") { - check_fs_installed() - fs::path(..., ext = ext) + check_fs_installed() + fs::path(..., ext = ext) } fs_file_copy <- function( - path, - new_path, - overwrite = FALSE + path, + new_path, + overwrite = FALSE ) { - check_fs_installed() - fs::file_copy( - path = path, - new_path = new_path, - overwrite - ) + check_fs_installed() + fs::file_copy( + path = path, + new_path = new_path, + overwrite + ) } fs_dir_copy <- function( - path, - new_path, - overwrite = FALSE + path, + new_path, + overwrite = FALSE ) { - check_fs_installed() - fs::dir_copy( - path, - new_path, - overwrite - ) + check_fs_installed() + fs::dir_copy( + path, + new_path, + overwrite + ) } diff --git a/R/bootstrap_attachment.R b/R/bootstrap_attachment.R index 08e65c16..887b6939 100644 --- a/R/bootstrap_attachment.R +++ b/R/bootstrap_attachment.R @@ -1,23 +1,23 @@ # All the fns here check that {attachment} is installed # before doing anything. check_attachment_installed <- function() { - rlang::check_installed( - "attachment", - version = "0.2.5", - reason = "to build a Dockerfile." - ) + rlang::check_installed( + "attachment", + version = "0.2.5", + reason = "to build a Dockerfile." + ) } attachment_create_renv_for_prod <- function( - path = ".", - output = "renv.lock.prod", - dev_pkg = "remotes", - ... + path = ".", + output = "renv.lock.prod", + dev_pkg = "remotes", + ... ) { - attachment::create_renv_for_prod( - path = path, - output = output, - dev_pkg = dev_pkg, - ... - ) + attachment::create_renv_for_prod( + path = path, + output = output, + dev_pkg = dev_pkg, + ... + ) } diff --git a/R/bootstrap_dockerfiler.R b/R/bootstrap_dockerfiler.R index 5dd79aad..9d284875 100644 --- a/R/bootstrap_dockerfiler.R +++ b/R/bootstrap_dockerfiler.R @@ -1,68 +1,68 @@ # All the fns here check that {dockerfiler} is installed # before doing anything. check_dockerfiler_installed <- function() { - rlang::check_installed( - "dockerfiler", - version = "0.2.0", - reason = "to build a Dockerfile." - ) + rlang::check_installed( + "dockerfiler", + version = "0.2.0", + reason = "to build a Dockerfile." + ) } dockerfiler_dock_from_renv <- function( - lockfile = "renv.lock", - distro = "focal", - FROM = "rocker/r-base", - AS = NULL, - sysreqs = TRUE, - repos = c(CRAN = "https://cran.rstudio.com/"), - expand = FALSE, - extra_sysreqs = NULL + lockfile = "renv.lock", + distro = "focal", + FROM = "rocker/r-base", + AS = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + extra_sysreqs = NULL ) { - check_dockerfiler_installed() - dockerfiler::dock_from_renv( - lockfile = lockfile, - distro = distro, - FROM = FROM, - AS = AS, - sysreqs = sysreqs, - repos = repos, - expand = expand, - extra_sysreqs = extra_sysreqs - ) + check_dockerfiler_installed() + dockerfiler::dock_from_renv( + lockfile = lockfile, + distro = distro, + FROM = FROM, + AS = AS, + sysreqs = sysreqs, + repos = repos, + expand = expand, + extra_sysreqs = extra_sysreqs + ) } dockerfiler_dock_from_desc <- function( - path = "DESCRIPTION", - FROM = paste0( - "rocker/r-ver:", - R.Version()$major, - ".", - R.Version()$minor - ), - AS = NULL, - sysreqs = TRUE, - repos = c(CRAN = "https://cran.rstudio.com/"), - expand = FALSE, - update_tar_gz = TRUE, - build_from_source = TRUE, - extra_sysreqs = NULL + path = "DESCRIPTION", + FROM = paste0( + "rocker/r-ver:", + R.Version()$major, + ".", + R.Version()$minor + ), + AS = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + update_tar_gz = TRUE, + build_from_source = TRUE, + extra_sysreqs = NULL ) { - check_dockerfiler_installed() - dockerfiler::dock_from_desc( - path = path, - FROM = FROM, - AS = AS, - sysreqs = sysreqs, - repos = repos, - expand = expand, - update_tar_gz = update_tar_gz, - build_from_source = build_from_source, - extra_sysreqs = extra_sysreqs - ) + check_dockerfiler_installed() + dockerfiler::dock_from_desc( + path = path, + FROM = FROM, + AS = AS, + sysreqs = sysreqs, + repos = repos, + expand = expand, + update_tar_gz = update_tar_gz, + build_from_source = build_from_source, + extra_sysreqs = extra_sysreqs + ) } dockerfiler_Dockerfile <- function() { - check_dockerfiler_installed() - dockerfiler::Dockerfile + check_dockerfiler_installed() + dockerfiler::Dockerfile } diff --git a/R/bootstrap_pkgload.R b/R/bootstrap_pkgload.R index 3c90630a..c2666a5a 100644 --- a/R/bootstrap_pkgload.R +++ b/R/bootstrap_pkgload.R @@ -1,40 +1,40 @@ # All the fns here check that {pkgload} is installed # before doing anything. check_pkgload_installed <- function() { - rlang::check_installed( - "pkgload", - reason = "to load the package." - ) + rlang::check_installed( + "pkgload", + reason = "to load the package." + ) } -uses_testthat <- getFromNamespace( "uses_testthat", "pkgload" ) +uses_testthat <- getFromNamespace("uses_testthat", "pkgload") pkgload_load_all <- function( - path = ".", - reset = TRUE, - compile = NA, - attach = TRUE, - export_all = TRUE, - export_imports = export_all, - helpers = TRUE, - attach_testthat = uses_testthat(path), - quiet = NULL, - recompile = FALSE, - warn_conflicts = TRUE + path = ".", + reset = TRUE, + compile = NA, + attach = TRUE, + export_all = TRUE, + export_imports = export_all, + helpers = TRUE, + attach_testthat = uses_testthat(path), + quiet = NULL, + recompile = FALSE, + warn_conflicts = TRUE ) { - check_roxygen2_installed() - pkgload::load_all( - path = path, - reset = reset, - compile = compile, - attach = attach, - export_all = export_all, - export_imports = export_imports, - helpers = helpers, - attach_testthat = attach_testthat, - quiet = quiet, - recompile = recompile, - warn_conflicts = warn_conflicts - ) + check_roxygen2_installed() + pkgload::load_all( + path = path, + reset = reset, + compile = compile, + attach = attach, + export_all = export_all, + export_imports = export_imports, + helpers = helpers, + attach_testthat = attach_testthat, + quiet = quiet, + recompile = recompile, + warn_conflicts = warn_conflicts + ) } diff --git a/R/bootstrap_roxygen2.R b/R/bootstrap_roxygen2.R index e836517c..f958842a 100644 --- a/R/bootstrap_roxygen2.R +++ b/R/bootstrap_roxygen2.R @@ -1,23 +1,23 @@ # All the fns here check that {roxygen2} is installed # before doing anything. check_roxygen2_installed <- function() { - rlang::check_installed( - "roxygen2", - reason = "to document the package." - ) + rlang::check_installed( + "roxygen2", + reason = "to document the package." + ) } roxygen2_roxygenise <- function( - package.dir = ".", - roclets = NULL, - load_code = NULL, - clean = FALSE + package.dir = ".", + roclets = NULL, + load_code = NULL, + clean = FALSE ) { - check_roxygen2_installed() - roxygen2::roxygenise( - package.dir = package.dir, - roclets = roclets, - load_code = load_code, - clean = clean - ) + check_roxygen2_installed() + roxygen2::roxygenise( + package.dir = package.dir, + roclets = roclets, + load_code = load_code, + clean = clean + ) } diff --git a/R/bootstrap_usethis.R b/R/bootstrap_usethis.R index a153d78b..1e513da5 100644 --- a/R/bootstrap_usethis.R +++ b/R/bootstrap_usethis.R @@ -2,115 +2,115 @@ # All the fns here check that {usethis} is installed # before doing anything. check_usethis_installed <- function(reason = "for project and file manipulation.") { - rlang::check_installed( - "usethis", - version = "1.6.0", - reason = reason - ) + rlang::check_installed( + "usethis", + version = "1.6.0", + reason = reason + ) } usethis_use_build_ignore <- function( - files, - escape = TRUE + files, + escape = TRUE ) { - check_usethis_installed( - reason = "to ignore files in the build." - ) - usethis::use_build_ignore( - files, - escape - ) + check_usethis_installed( + reason = "to ignore files in the build." + ) + usethis::use_build_ignore( + files, + escape + ) } usethis_use_package <- function( - package, - type = "Imports", - min_version = NULL + package, + type = "Imports", + min_version = NULL ) { - check_usethis_installed( - reason = "to add dependencies to DESCRIPTION." - ) - usethis::use_package( - package, - type, - min_version - ) + check_usethis_installed( + reason = "to add dependencies to DESCRIPTION." + ) + usethis::use_package( + package, + type, + min_version + ) } usethis_create_project <- function( - path, - rstudio = rstudioapi::isAvailable(), - open = rlang::is_interactive() + path, + rstudio = rstudioapi::isAvailable(), + open = rlang::is_interactive() ) { - check_usethis_installed( - reason = "to create a project." - ) - usethis::create_project( - path, - rstudio, - open - ) + check_usethis_installed( + reason = "to create a project." + ) + usethis::create_project( + path, + rstudio, + open + ) } usethis_use_latest_dependencies <- function( - overwrite = FALSE, - source = c("local", "CRAN") + overwrite = FALSE, + source = c("local", "CRAN") ) { - check_usethis_installed( - reason = "to set dependency version." - ) - usethis::use_latest_dependencies( - overwrite, - source - ) + check_usethis_installed( + reason = "to set dependency version." + ) + usethis::use_latest_dependencies( + overwrite, + source + ) } usethis_proj_set <- function( - path = ".", - force = FALSE + path = ".", + force = FALSE ) { - check_usethis_installed( - reason = "to set project." - ) - usethis::proj_set( - path, - force - ) + check_usethis_installed( + reason = "to set project." + ) + usethis::proj_set( + path, + force + ) } usethis_use_testthat <- function( - edition = NULL, - parallel = FALSE + edition = NULL, + parallel = FALSE ) { - check_usethis_installed( - reason = "to add {testthat} infrastructure." - ) - usethis::use_testthat( - edition, - parallel - ) + check_usethis_installed( + reason = "to add {testthat} infrastructure." + ) + usethis::use_testthat( + edition, + parallel + ) } usethis_use_test <- function( - name = NULL, - open = rlang::is_interactive() + name = NULL, + open = rlang::is_interactive() ) { - check_usethis_installed( - reason = "to add tests." - ) - usethis::use_test( - name, - open - ) + check_usethis_installed( + reason = "to add tests." + ) + usethis::use_test( + name, + open + ) } usethis_use_spell_check <- function( - vignettes = TRUE, - lang = "en-US", - error = FALSE + vignettes = TRUE, + lang = "en-US", + error = FALSE ) { - check_usethis_installed( - reason = "to add spellcheck." - ) - usethis::use_spell_check( - vignettes, - lang, - error - ) + check_usethis_installed( + reason = "to add spellcheck." + ) + usethis::use_spell_check( + vignettes, + lang, + error + ) } diff --git a/R/create_golem.R b/R/create_golem.R index fb77355f..468f51ac 100644 --- a/R/create_golem.R +++ b/R/create_golem.R @@ -113,7 +113,7 @@ create_golem <- function( path = path_to_golem, open = FALSE ) - if (!file.exists(".here")){ + if (!file.exists(".here")) { here::set_here(path_to_golem) } cat_green_tick("Created package directory") diff --git a/R/modules_fn.R b/R/modules_fn.R index 989c6421..1476f12a 100644 --- a/R/modules_fn.R +++ b/R/modules_fn.R @@ -260,7 +260,7 @@ use_module_test <- function( "testthat", "to build the test structure." ) - + old <- setwd(fs_path_abs(pkg)) on.exit(setwd(old)) diff --git a/R/use_utils.R b/R/use_utils.R index ebe09768..d004b5e1 100644 --- a/R/use_utils.R +++ b/R/use_utils.R @@ -135,7 +135,6 @@ use_utils <- function( folder_name, pkg = get_golem_wd() ) { - old <- setwd( fs_path_abs(pkg) ) diff --git a/R/utils.R b/R/utils.R index f6498796..a461e9a9 100644 --- a/R/utils.R +++ b/R/utils.R @@ -115,10 +115,10 @@ remove_comments <- function(file) { cat_green_tick <- function(...) { do_if_unquiet({ cat_bullet( - ..., - bullet = "tick", - bullet_col = "green" - ) + ..., + bullet = "tick", + bullet_col = "green" + ) }) } @@ -144,9 +144,7 @@ cat_info <- function(...) { }) } -cat_rule <- function( - ... -) { +cat_rule <- function(...) { do_if_unquiet({ cli::cat_rule( ... @@ -154,11 +152,9 @@ cat_rule <- function( }) } -cat_line <- function( - ... -) { +cat_line <- function(...) { do_if_unquiet({ - cli::cat_line( + cli::cat_line( ... ) }) @@ -480,18 +476,16 @@ check_name_length <- function(name) { ) } -do_if_unquiet <- function( - expr -){ - if( - ! getOption( - "golem.quiet", +do_if_unquiet <- function(expr) { + if ( + !getOption( + "golem.quiet", getOption( - "usethis.quiet", + "usethis.quiet", default = FALSE - ) + ) ) - ){ + ) { force(expr) } -} \ No newline at end of file +} diff --git a/tests/testthat/helper-config.R b/tests/testthat/helper-config.R index f50b9073..7c80580b 100644 --- a/tests/testthat/helper-config.R +++ b/tests/testthat/helper-config.R @@ -81,7 +81,7 @@ rand_name <- function() { withr::with_dir(pkg, { # Some weird things with {here} unloadNamespace("here") - if (!file.exists(".here")){ + if (!file.exists(".here")) { here::set_here(path_to_golem) } set_golem_options() diff --git a/tests/testthat/test-add_deploy_helpers.R b/tests/testthat/test-add_deploy_helpers.R index 0bbe2181..70d9e9e0 100644 --- a/tests/testthat/test-add_deploy_helpers.R +++ b/tests/testthat/test-add_deploy_helpers.R @@ -13,13 +13,14 @@ test_that("add_dockerfiles", { "Dockerfile", { withr::with_options( - c("golem.quiet" = FALSE),{ + c("golem.quiet" = FALSE), + { output <- testthat::capture_output( fun(pkg = pkg, sysreqs = FALSE, open = FALSE) ) } ) - + expect_exists("Dockerfile") test <- stringr::str_detect( output, @@ -43,28 +44,30 @@ test_that("add_dockerfiles repos variation", { c("Dockerfile1", "Dockerfile2"), { withr::with_options( - c("golem.quiet" = FALSE),{ - output1 <- testthat::capture_output( - fun( - pkg = pkg, - sysreqs = FALSE, - open = FALSE, - repos = "https://cran.rstudio.com/", - output = "Dockerfile1" + c("golem.quiet" = FALSE), + { + output1 <- testthat::capture_output( + fun( + pkg = pkg, + sysreqs = FALSE, + open = FALSE, + repos = "https://cran.rstudio.com/", + output = "Dockerfile1" + ) ) - ) - output2 <- testthat::capture_output( - fun( - pkg = pkg, - sysreqs = FALSE, - open = FALSE, - repos = c("https://cran.rstudio.com/"), - output = "Dockerfile2" + output2 <- testthat::capture_output( + fun( + pkg = pkg, + sysreqs = FALSE, + open = FALSE, + repos = c("https://cran.rstudio.com/"), + output = "Dockerfile2" + ) ) - ) - expect_exists("Dockerfile1") - expect_exists("Dockerfile2") - }) + expect_exists("Dockerfile1") + expect_exists("Dockerfile2") + } + ) test1 <- stringr::str_detect( output1, @@ -98,15 +101,17 @@ test_that("add_rstudio_files", { burn_after_reading( "app.R", { - withr::with_options( - c("golem.quiet" = FALSE),{ - output <- testthat::capture_output( - fun( - pkg = pkg, - open = FALSE + withr::with_options( + c("golem.quiet" = FALSE), + { + output <- testthat::capture_output( + fun( + pkg = pkg, + open = FALSE + ) ) + } ) - }) expect_exists("app.R") test <- stringr::str_detect( output, diff --git a/tests/testthat/test-add_modules.R b/tests/testthat/test-add_modules.R index af70b65b..85c767ea 100644 --- a/tests/testthat/test-add_modules.R +++ b/tests/testthat/test-add_modules.R @@ -16,9 +16,11 @@ test_that("add_module", { ## Test message of function remove_file("R/mod_output.R") withr::with_options( - c("golem.quiet" = FALSE),{ - output <- testthat::capture_output(add_module("output", open = FALSE)) - }) + c("golem.quiet" = FALSE), + { + output <- testthat::capture_output(add_module("output", open = FALSE)) + } + ) expect_true( stringr::str_detect(output, "File created at R/mod_output.R") ) diff --git a/tests/testthat/test-desc.R b/tests/testthat/test-desc.R index e147f82e..6b851eef 100644 --- a/tests/testthat/test-desc.R +++ b/tests/testthat/test-desc.R @@ -2,7 +2,8 @@ test_that("desc works", { with_dir(pkg, { withr::with_options( - c("golem.quiet" = FALSE),{ + c("golem.quiet" = FALSE), + { output <- capture_output( fill_desc( pkg_name = fakename, @@ -14,8 +15,9 @@ test_that("desc works", { repo_url = "http://repo_url.com", pkg_version = "0.0.0.9000" ) - ) - }) + ) + } + ) add_desc <- c( fakename, "newtitle", diff --git a/tests/testthat/test-extra_sysreqs.R b/tests/testthat/test-extra_sysreqs.R index 286f0999..53b906cb 100644 --- a/tests/testthat/test-extra_sysreqs.R +++ b/tests/testthat/test-extra_sysreqs.R @@ -13,18 +13,20 @@ test_that("test extra sysreqs", { burn_after_reading( "Dockerfile", { - withr::with_options( - c("golem.quiet" = FALSE),{ - output <- testthat::capture_output( - fun( - pkg = pkg, - sysreqs = FALSE, - open = FALSE, - extra_sysreqs = c("test1", "test2"), - output = "Dockerfile" - ) + withr::with_options( + c("golem.quiet" = FALSE), + { + output <- testthat::capture_output( + fun( + pkg = pkg, + sysreqs = FALSE, + open = FALSE, + extra_sysreqs = c("test1", "test2"), + output = "Dockerfile" + ) + ) + } ) - }) expect_exists("Dockerfile") test <- stringr::str_detect( output, diff --git a/tests/testthat/test-make_dev.R b/tests/testthat/test-make_dev.R index 5f736b7a..66013a26 100644 --- a/tests/testthat/test-make_dev.R +++ b/tests/testthat/test-make_dev.R @@ -61,9 +61,11 @@ test_that("test print_dev", { test_that("test browser_button", { withr::with_options( - c("golem.quiet" = FALSE),{ - output <- capture_output_lines(browser_button()) - }) + c("golem.quiet" = FALSE), + { + output <- capture_output_lines(browser_button()) + } + ) expect_true( grepl('actionButton\\("browser", "browser"\\)', output[2]) ) diff --git a/tests/testthat/test-test_helpers.R b/tests/testthat/test-test_helpers.R index 82aa04c2..307e7e3d 100644 --- a/tests/testthat/test-test_helpers.R +++ b/tests/testthat/test-test_helpers.R @@ -1,19 +1,23 @@ test_that("test expect_shinytag", { with_dir(pkg, { withr::with_options( - c("golem.quiet" = FALSE),{ + c("golem.quiet" = FALSE), + { expect_equal(capture_output(expect_shinytag(favicon("jean"))), "") expect_error(expect_shinytag("pierre")) - }) + } + ) }) }) test_that("test expect_shinytaglist", { with_dir(pkg, { withr::with_options( - c("golem.quiet" = FALSE),{ + c("golem.quiet" = FALSE), + { expect_equal(capture_output(expect_shinytaglist(shiny::tagList())), "") expect_error(expect_shinytaglist("test")) - }) + } + ) }) }) From f8461c227e07a8e3b80f2e1e2779734ca96365e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Br=C3=A9ant?= <35060481+ArthurData@users.noreply.github.com> Date: Fri, 28 Oct 2022 11:58:33 +0200 Subject: [PATCH 19/55] feat: remove {desc} as hard dep (#940) --- DESCRIPTION | 4 +-- NAMESPACE | 2 -- R/add_dockerfiles.R | 1 - R/bootstrap_desc.R | 40 ++++++++++++++++++++++++++++ R/create_golem.R | 5 ++++ R/desc.R | 3 +-- R/golem-yaml-set.R | 4 +-- R/reload.R | 2 +- README.Rmd | 7 +---- README.md | 7 +---- inst/mantests/build.R | 24 ++++++++--------- tests/testthat/helper-config.R | 4 ++- tests/testthat/test-desc.R | 1 + tests/testthat/test-use_recomended.R | 3 ++- 14 files changed, 71 insertions(+), 36 deletions(-) create mode 100644 R/bootstrap_desc.R diff --git a/DESCRIPTION b/DESCRIPTION index b0011c5d..ac647cab 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -53,7 +53,6 @@ Imports: cli (>= 2.0.0), config, crayon, - desc, here, htmltools, rlang (>= 1.0.0), @@ -83,7 +82,8 @@ Suggests: attachment (>= 0.2.5), renv, usethis (>= 1.6.0), - fs + fs, + desc VignetteBuilder: knitr Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 7cdfebe7..0369c546 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -96,8 +96,6 @@ importFrom(cli,cat_line) importFrom(cli,cat_rule) importFrom(cli,cli_alert_info) importFrom(config,get) -importFrom(desc,desc_get_deps) -importFrom(desc,description) importFrom(htmltools,htmlDependency) importFrom(rstudioapi,documentSaveAll) importFrom(rstudioapi,getSourceEditorContext) diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index 323eae56..b5632c95 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -47,7 +47,6 @@ talk_once <- function(.f, msg = "") { #' @export #' @rdname dockerfiles #' -#' @importFrom desc desc_get_deps #' @importFrom rstudioapi navigateToFile isAvailable hasFun #' #' @examples diff --git a/R/bootstrap_desc.R b/R/bootstrap_desc.R new file mode 100644 index 00000000..a91196df --- /dev/null +++ b/R/bootstrap_desc.R @@ -0,0 +1,40 @@ +# All the fns here check that {desc} is installed +# before doing anything. +check_desc_installed <- function() { + rlang::check_installed( + "desc", + reason = "to fill DESCRIPTION." + ) +} + +desc_description <- function(file) { + check_desc_installed() + desc::description$new( + file = file + ) +} + +desc_get <- function(keys) { + check_desc_installed() + desc::desc_get(keys) +} + +desc_get_version <- function() { + check_desc_installed() + desc::desc_get_version() +} + +desc_get_deps <- function(file = NULL) { + check_desc_installed() + desc::desc_get_deps(file) +} + +desc_get_field <- function(key) { + check_desc_installed() + desc::desc_get_field(key) +} + +desc_get_author <- function() { + check_desc_installed() + desc::desc_get_author() +} diff --git a/R/create_golem.R b/R/create_golem.R index 468f51ac..3c8a6f04 100644 --- a/R/create_golem.R +++ b/R/create_golem.R @@ -197,6 +197,11 @@ create_golem <- function( old <- setwd(path_to_golem) + + if (!requireNamespace("desc", quietly = TRUE)) { + check_desc_installed() + } # incase of {desc} not installed by {usethis} + usethis_use_latest_dependencies() # No .Rprofile for now diff --git a/R/desc.R b/R/desc.R index ffb68d8a..074ca81b 100644 --- a/R/desc.R +++ b/R/desc.R @@ -11,7 +11,6 @@ #' @param pkg_version The version of the package. Default is 0.0.0.9000 #' @param pkg Path to look for the DESCRIPTION. Default is `get_golem_wd()`. #' -#' @importFrom desc description #' @importFrom cli cat_bullet #' #' @export @@ -31,7 +30,7 @@ fill_desc <- function( ) { path <- fs_path_abs(pkg) - desc <- desc::description$new( + desc <- desc_description( file = fs_path(path, "DESCRIPTION") ) diff --git a/R/golem-yaml-set.R b/R/golem-yaml-set.R index 4e5c26c3..6326acad 100644 --- a/R/golem-yaml-set.R +++ b/R/golem-yaml-set.R @@ -50,7 +50,7 @@ set_golem_name <- function( ) # Changing in DESCRIPTION - desc <- desc::description$new( + desc <- desc_description( file = fs_path( path, "DESCRIPTION" @@ -84,7 +84,7 @@ set_golem_version <- function( talkative = talkative ) - desc <- desc::description$new( + desc <- desc_description( file = fs_path( path, "DESCRIPTION" diff --git a/R/reload.R b/R/reload.R index 2bb9e51f..759a9a48 100644 --- a/R/reload.R +++ b/R/reload.R @@ -34,7 +34,7 @@ detach_all_attached <- function() { check_name_consistency <- function(pkg) { old_dir <- setwd(pkg) - package_name <- desc::desc_get("Package") + package_name <- desc_get(keys = "Package") pth <- fs_path( pkg, "R", diff --git a/README.Rmd b/README.Rmd index 61060376..468a9f85 100644 --- a/README.Rmd +++ b/README.Rmd @@ -27,12 +27,7 @@ knitr::opts_chunk$set( ## About -You're reading the doc about version : - -```{r eval = TRUE} -desc::desc_get_version() -``` - +You're reading the doc about version : ``r as.data.frame(read.dcf("DESCRIPTION"))$Version `` ## Tool series diff --git a/README.md b/README.md index d241396b..d90de195 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,7 @@ shiny applications. ## About -You’re reading the doc about version : - -``` r -desc::desc_get_version() -#> [1] '0.3.3.9000' -``` +You’re reading the doc about version : `0.3.4.9002` ## Tool series diff --git a/inst/mantests/build.R b/inst/mantests/build.R index 0cc9aa44..3e761bf1 100644 --- a/inst/mantests/build.R +++ b/inst/mantests/build.R @@ -69,7 +69,7 @@ install_local( ) golem::install_dev_deps( - force_install = TRUE, + force_install = TRUE, lib = temp_lib ) @@ -145,19 +145,19 @@ withr::with_tempdir({ file.exists("LICENSE") ) expect_true( - desc::desc_get("License") == "MIT + file LICENSE" + desc_get("License") == "MIT + file LICENSE" ) cat_ok() cli::cat_rule("Checking the DESCRIPTION is correct") expect_true( - desc::desc_get("Package") == "golemmetrics" + desc_get("Package") == "golemmetrics" ) expect_true( - desc::desc_get("Title") == "An Amazing Shiny App" + desc_get("Title") == "An Amazing Shiny App" ) expect_true( - all(desc::desc_get_deps()$package %in% c("config", "golem", "shiny")) + all(desc_get_deps()$package %in% c("config", "golem", "shiny")) ) cat_ok() @@ -210,31 +210,31 @@ withr::with_tempdir({ cli::cat_rule("checking package name") expect_equal( - desc::desc_get_field("Package"), + desc_get_field("Package"), "golemmetrics" ) cat_ok() cli::cat_rule("checking pkg_title name") expect_equal( - desc::desc_get_field("Title"), + desc_get_field("Title"), "A App with Metrics about 'Golem'" ) cat_ok() cli::cat_rule("checking package name") expect_equal( - desc::desc_get_field("Description"), + desc_get_field("Description"), "Read metrics about {golem}." ) cat_ok() cli::cat_rule("checking package name") expect_equal( - as.character(desc::desc_get_author()), + as.character(desc_get_author()), "Colin Fay [cre, aut]" ) cat_ok() cli::cat_rule("checking package version") expect_equal( - as.character(desc::desc_get_version()), + as.character(desc_get_version()), "0.0.0.9000" ) cat_ok() @@ -265,7 +265,7 @@ withr::with_tempdir({ # usethis::use_mit_license( "Golem User" ) expect_equal( - desc::desc_get_field("License"), + desc_get_field("License"), "MIT + file LICENSE" ) expect_true( @@ -321,7 +321,7 @@ withr::with_tempdir({ } usethis::use_package("cranlogs") expect_true( - "cranlogs" %in% desc::desc_get_deps()$package + "cranlogs" %in% desc_get_deps()$package ) cat_ok() diff --git a/tests/testthat/helper-config.R b/tests/testthat/helper-config.R index 7c80580b..5105773b 100644 --- a/tests/testthat/helper-config.R +++ b/tests/testthat/helper-config.R @@ -84,7 +84,9 @@ withr::with_dir(pkg, { if (!file.exists(".here")) { here::set_here(path_to_golem) } - set_golem_options() + if (requireNamespace("desc", quietly = TRUE)) { + set_golem_options() + } usethis::proj_set(pkg) orig_test <- set_golem_wd( pkg = pkg diff --git a/tests/testthat/test-desc.R b/tests/testthat/test-desc.R index 6b851eef..7561442f 100644 --- a/tests/testthat/test-desc.R +++ b/tests/testthat/test-desc.R @@ -1,5 +1,6 @@ test_that("desc works", { + testthat::skip_if_not_installed("desc") with_dir(pkg, { withr::with_options( c("golem.quiet" = FALSE), diff --git a/tests/testthat/test-use_recomended.R b/tests/testthat/test-use_recomended.R index 738c7370..cb457b13 100644 --- a/tests/testthat/test-use_recomended.R +++ b/tests/testthat/test-use_recomended.R @@ -1,5 +1,6 @@ test_that("test use_recommended_deps", { testthat::skip_on_cran() + testthat::skip_if_not_installed("desc") with_dir(pkg, { packages <- c("shiny", "DT", "attempt", "glue", "golem", "htmltools") to_add <- c() @@ -11,7 +12,7 @@ test_that("test use_recommended_deps", { expect_warning( use_recommended_deps(recommended = to_add) ) - deps <- desc::desc_get_deps(file = "DESCRIPTION") + deps <- desc_get_deps(file = "DESCRIPTION") expect_true( all(to_add %in% deps$package) ) From 43a40f4f070bdd3fc3ccf6819bebb6c9467ccf61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Br=C3=A9ant?= Date: Fri, 28 Oct 2022 17:26:20 +0200 Subject: [PATCH 20/55] feat: Create html template for maintenance mode Issue Add a maintenance mode ? #820 --- NAMESPACE | 2 + R/with_opt.R | 33 +++- inst/app/maintenance.html | 274 ++++++++++++++++++++++++++++++ man/maintenance_page.Rd | 14 ++ man/with_golem_options.Rd | 9 +- tests/testthat/test-maintenance.R | 4 + 6 files changed, 330 insertions(+), 6 deletions(-) create mode 100644 inst/app/maintenance.html create mode 100644 man/maintenance_page.Rd create mode 100644 tests/testthat/test-maintenance.R diff --git a/NAMESPACE b/NAMESPACE index 0369c546..6848cce5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -52,6 +52,7 @@ export(invoke_js) export(is_running) export(js_handler_template) export(js_template) +export(maintenance_page) export(make_dev) export(message_dev) export(module_template) @@ -107,6 +108,7 @@ importFrom(rstudioapi,openProject) importFrom(rstudioapi,sourceMarkers) importFrom(shiny,addResourcePath) importFrom(shiny,getShinyOption) +importFrom(shiny,htmlTemplate) importFrom(shiny,includeScript) importFrom(shiny,tags) importFrom(utils,capture.output) diff --git a/R/with_opt.R b/R/with_opt.R index 14af6d68..2da07dba 100644 --- a/R/with_opt.R +++ b/R/with_opt.R @@ -6,17 +6,25 @@ #' #' @param app the app object. #' @param golem_opts A list of Options to be added to the app +#' @param maintenance_page an html_document or a shiny tag list. By default is golem page #' @param print Whether or not to print the app. Default is to `FALSE`, which #' should be what you need 99.99% of the time In case you need to #' actively print the app object, you can set it to `TRUE`. #' #' @return a shiny.appObj object #' @export -with_golem_options <- function( - app, - golem_opts, - print = FALSE -) { +with_golem_options <- function(app, + golem_opts, + maintenance_page = golem::maintenance_page, + print = FALSE) { + + # Check if app is in maintenance + if (Sys.getenv("GOLEM_SET_MAINTENANCE_ACTIVE") == "TRUE") { + app <- shiny::shinyApp( + ui = maintenance_page, + server = function(input, output, session) {} + ) + } # Setting the running option set_golem_global( @@ -105,3 +113,18 @@ get_golem_options <- function(which = NULL) { getShinyOption("golem_options")[[which]] } } + +#' maintenance_page +#' +#' A default html page for maintenance mode +#' +#' @importFrom shiny htmlTemplate +#' +#' @return an html_document +#' +#' @export +maintenance_page <- function() { + shiny::htmlTemplate( + filename = system.file("app", "maintenance.html", package = "golem") + ) +} diff --git a/inst/app/maintenance.html b/inst/app/maintenance.html new file mode 100644 index 00000000..6566c4ca --- /dev/null +++ b/inst/app/maintenance.html @@ -0,0 +1,274 @@ + + + + + + + Coming soon... + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/man/maintenance_page.Rd b/man/maintenance_page.Rd new file mode 100644 index 00000000..148e3932 --- /dev/null +++ b/man/maintenance_page.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/with_opt.R +\name{maintenance_page} +\alias{maintenance_page} +\title{maintenance_page} +\usage{ +maintenance_page() +} +\value{ +an html_document +} +\description{ +A default html page for maintenance mode +} diff --git a/man/with_golem_options.Rd b/man/with_golem_options.Rd index 21bb7303..05b595c9 100644 --- a/man/with_golem_options.Rd +++ b/man/with_golem_options.Rd @@ -4,13 +4,20 @@ \alias{with_golem_options} \title{Add Golem options to a Shiny App} \usage{ -with_golem_options(app, golem_opts, print = FALSE) +with_golem_options( + app, + golem_opts, + maintenance_page = golem::maintenance_page, + print = FALSE +) } \arguments{ \item{app}{the app object.} \item{golem_opts}{A list of Options to be added to the app} +\item{maintenance_page}{an html_document or a shiny tag list. By default is golem page} + \item{print}{Whether or not to print the app. Default is to \code{FALSE}, which should be what you need 99.99\% of the time In case you need to actively print the app object, you can set it to \code{TRUE}.} diff --git a/tests/testthat/test-maintenance.R b/tests/testthat/test-maintenance.R new file mode 100644 index 00000000..8464e04f --- /dev/null +++ b/tests/testthat/test-maintenance.R @@ -0,0 +1,4 @@ +test_that("test maintenance_page", { + html <- maintenance_page() + expect_true(inherits(html, c("html_document", "shiny.tag.list", "list"))) +}) From 568a624a172137f1bb04b5cd211bd87662f0ba69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Br=C3=A9ant?= Date: Mon, 31 Oct 2022 23:55:27 +0100 Subject: [PATCH 21/55] feat: Create documentation for maintenance page --- vignettes/f_extending_golem.Rmd | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/vignettes/f_extending_golem.Rmd b/vignettes/f_extending_golem.Rmd index 5f14c655..f16deb7d 100644 --- a/vignettes/f_extending_golem.Rmd +++ b/vignettes/f_extending_golem.Rmd @@ -198,6 +198,94 @@ my_tmpl <- function(path, ...) { golem::add_css_file(name = "custom", template = my_tmpl) ``` +## Use a maintenance module +## What it is +When you need to pause your application for some reasons: breaking changes, database update, etc., you can use a __maintenance mode__. +During the maintenance period, your application will be paused and a warning message will be displayed to your users. +{golem} comes with a default maintenance page. But, you can replace it with you own maintenance page. + +## How to set the maintenance mode + +To use a maintenance mode, you have to create a an environment variable `GOLEM_SET_MAINTENANCE_ACTIVE`. + +```{r} +usethis::edit_r_environ(scope = "project") +``` + +Then create the environment variable: + +```{r} +GOLEM_SET_MAINTENANCE_ACTIVE=TRUE +``` + +To see the effects, restart your session: + +```{r} +rstudioapi::restartSession() +``` + +## The maintenance page + +By default, {golem} comes with a default maintenance page. + +You can override it and use your own custom maintenance page. + +You have to pass a `html_document` or a `shiny tag list`. For that, go to to your `run_app.R` : + +```{r} +rstudioapi::navigateToFile("R/run_app.R") +``` + +Then, use the `maintenance_page` parameter from `with_golem_options`: + +```{r} +run_app <- function(onStart = NULL, + options = list(), + enableBookmarking = NULL, + uiPattern = "/", + ...) { + with_golem_options( + app = shinyApp( + ui = app_ui, + server = app_server, + onStart = onStart, + options = options, + enableBookmarking = enableBookmarking, + uiPattern = uiPattern + ), + golem_opts = list(...), + maintenance_page = shiny::htmlTemplate(filename = app_sys("your_custom.html")) + ) +} +``` + +or: + +```{r} +run_app <- function(onStart = NULL, + options = list(), + enableBookmarking = NULL, + uiPattern = "/", + ...) { + with_golem_options( + app = shinyApp( + ui = app_ui, + server = app_server, + onStart = onStart, + options = options, + enableBookmarking = enableBookmarking, + uiPattern = uiPattern + ), + golem_opts = list(...), + maintenance_page = tagList( + fluidRow( + h1("Under maintenance"), + span("Coming soon...") + ) + ) + ) +} +``` \ No newline at end of file From 32673239f7d898bfa9fa44ab8c5766e6610393fa Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 7 Nov 2022 13:52:56 +0100 Subject: [PATCH 22/55] refactor: changed the text on screen for maintenance page --- inst/app/maintenance.html | 522 +++++++++++++++++++------------------- 1 file changed, 258 insertions(+), 264 deletions(-) diff --git a/inst/app/maintenance.html b/inst/app/maintenance.html index 6566c4ca..ed996309 100644 --- a/inst/app/maintenance.html +++ b/inst/app/maintenance.html @@ -1,274 +1,268 @@ - - - - Coming soon... - + + + + Under Maintenance + -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file From f32f75334e390cf82987d4313d85fc4e33520b87 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 7 Nov 2022 13:53:16 +0100 Subject: [PATCH 23/55] refactor: renamed env var to GOLEM_MAINTENANCE_ACTIVE --- R/with_opt.R | 30 ++++++++++++++++++------------ man/with_golem_options.Rd | 8 ++++---- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/R/with_opt.R b/R/with_opt.R index 2da07dba..3b33a40b 100644 --- a/R/with_opt.R +++ b/R/with_opt.R @@ -5,21 +5,23 @@ #' launch. #' #' @param app the app object. -#' @param golem_opts A list of Options to be added to the app -#' @param maintenance_page an html_document or a shiny tag list. By default is golem page +#' @param golem_opts A list of options to be added to the app +#' @param maintenance_page an html_document or a shiny tag list. Default is golem template. #' @param print Whether or not to print the app. Default is to `FALSE`, which -#' should be what you need 99.99% of the time In case you need to -#' actively print the app object, you can set it to `TRUE`. +#' should be what you need 99.99% of the time. In case you need to +#' actively print() the app object, you can set it to `TRUE`. #' #' @return a shiny.appObj object #' @export -with_golem_options <- function(app, - golem_opts, - maintenance_page = golem::maintenance_page, - print = FALSE) { +with_golem_options <- function( + app, + golem_opts, + maintenance_page = golem::maintenance_page, + print = FALSE +) { # Check if app is in maintenance - if (Sys.getenv("GOLEM_SET_MAINTENANCE_ACTIVE") == "TRUE") { + if (Sys.getenv("GOLEM_MAINTENANCE_ACTIVE", "FALSE") == "TRUE") { app <- shiny::shinyApp( ui = maintenance_page, server = function(input, output, session) {} @@ -49,9 +51,9 @@ with_golem_options <- function(app, print <- FALSE } - # Almost all cases will be ok with explicitely printing the + # Almost all cases will be ok with not explicitely printing the # application object, but for corner cases like direct shinyApp - # object manipulation, this feature can be turned off + # object manipulation, this feature can be turned on if (print) { print(app) } else { @@ -125,6 +127,10 @@ get_golem_options <- function(which = NULL) { #' @export maintenance_page <- function() { shiny::htmlTemplate( - filename = system.file("app", "maintenance.html", package = "golem") + filename = system.file( + "app", + "maintenance.html", + package = "golem" + ) ) } diff --git a/man/with_golem_options.Rd b/man/with_golem_options.Rd index 05b595c9..ad35ab25 100644 --- a/man/with_golem_options.Rd +++ b/man/with_golem_options.Rd @@ -14,13 +14,13 @@ with_golem_options( \arguments{ \item{app}{the app object.} -\item{golem_opts}{A list of Options to be added to the app} +\item{golem_opts}{A list of options to be added to the app} -\item{maintenance_page}{an html_document or a shiny tag list. By default is golem page} +\item{maintenance_page}{an html_document or a shiny tag list. Default is golem template.} \item{print}{Whether or not to print the app. Default is to \code{FALSE}, which -should be what you need 99.99\% of the time In case you need to -actively print the app object, you can set it to \code{TRUE}.} +should be what you need 99.99\% of the time. In case you need to +actively print() the app object, you can set it to \code{TRUE}.} } \value{ a shiny.appObj object From cc608c97b1a53b5f5203b4a5cf1ee2b625312cfd Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 7 Nov 2022 13:53:29 +0100 Subject: [PATCH 24/55] doc: some vignette rewritting and additions --- vignettes/f_extending_golem.Rmd | 84 ++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/vignettes/f_extending_golem.Rmd b/vignettes/f_extending_golem.Rmd index f16deb7d..bb623ca5 100644 --- a/vignettes/f_extending_golem.Rmd +++ b/vignettes/f_extending_golem.Rmd @@ -198,55 +198,55 @@ my_tmpl <- function(path, ...) { golem::add_css_file(name = "custom", template = my_tmpl) ``` -## Use a maintenance module +## Turn on the maintenance mode ## What it is -When you need to pause your application for some reasons: breaking changes, database update, etc., you can use a __maintenance mode__. -During the maintenance period, your application will be paused and a warning message will be displayed to your users. +From time to time, you need your application to be unavailbel: database update, API changes, etc. +In order to keep your app running but make it unavailable, you can use a __maintenance mode__. +When this maintenance mode is turned on, your application will be paused and a specific page will be displayed to your users. -{golem} comes with a default maintenance page. But, you can replace it with you own maintenance page. +`{golem}` comes with a default maintenance page, and you can replace it with you own page. ## How to set the maintenance mode -To use a maintenance mode, you have to create a an environment variable `GOLEM_SET_MAINTENANCE_ACTIVE`. +The maintenance mode will be turned on whenever the R process detects that the `GOLEM_MAINTENANCE_ACTIVE` environment variable is set to TRUE. -```{r} -usethis::edit_r_environ(scope = "project") -``` - -Then create the environment variable: +To visualise the maintenance page locally, you can run the following: -```{r} -GOLEM_SET_MAINTENANCE_ACTIVE=TRUE +```{r eval = FALSE} +withr::with_envvar( + c("GOLEM_MAINTENANCE_ACTIVE" = TRUE), + { + golem::run_dev() + } +) ``` -To see the effects, restart your session: -```{r} -rstudioapi::restartSession() -``` +If you're deploying on Posit Connect, you can set this variable in the setup panel. -## The maintenance page +If in command line, you can also do -By default, {golem} comes with a default maintenance page. +``` +export GOLEM_MAINTENANCE_ACTIVE=TRUE && Rscript -e "mypkg::run_app()" +``` -You can override it and use your own custom maintenance page. -You have to pass a `html_document` or a `shiny tag list`. For that, go to to your `run_app.R` : +## The maintenance page -```{r} -rstudioapi::navigateToFile("R/run_app.R") -``` +`{golem}` comes with a default maintenance page, but you can override it and use your own custom page. -Then, use the `maintenance_page` parameter from `with_golem_options`: +In order to use your own page, you need to pass either an `html_document` or a `tagList` to the `with_golem_options` function in `run_app.R`: ```{r} -run_app <- function(onStart = NULL, - options = list(), - enableBookmarking = NULL, - uiPattern = "/", - ...) { +run_app <- function( + onStart = NULL, + options = list(), + enableBookmarking = NULL, + uiPattern = "/", + ... +) { with_golem_options( app = shinyApp( ui = app_ui, @@ -257,7 +257,12 @@ run_app <- function(onStart = NULL, uiPattern = uiPattern ), golem_opts = list(...), - maintenance_page = shiny::htmlTemplate(filename = app_sys("your_custom.html")) + maintenance_page = tagList( + fluidRow( + h1("Under maintenance"), + span("Coming soon...") + ) + ) ) } ``` @@ -265,11 +270,13 @@ run_app <- function(onStart = NULL, or: ```{r} -run_app <- function(onStart = NULL, - options = list(), - enableBookmarking = NULL, - uiPattern = "/", - ...) { +run_app <- function( + onStart = NULL, + options = list(), + enableBookmarking = NULL, + uiPattern = "/", + ... +) { with_golem_options( app = shinyApp( ui = app_ui, @@ -280,10 +287,9 @@ run_app <- function(onStart = NULL, uiPattern = uiPattern ), golem_opts = list(...), - maintenance_page = tagList( - fluidRow( - h1("Under maintenance"), - span("Coming soon...") + maintenance_page = shiny::htmlTemplate( + filename = app_sys( + "custom_maintenance_page.html" ) ) ) From acc054bfd24a8dfbc4b9b2ce6ca49682dfe443ea Mon Sep 17 00:00:00 2001 From: vincent guyader Date: Wed, 7 Dec 2022 13:39:29 +0100 Subject: [PATCH 25/55] Fix 944 and correct CI (#947) * fix #944 force lowercase for package name in Dockerfile * check_is_installed is back again instead of fs_file_copy for dockerfile creation * set version to 0.3.5.9001 --- NEWS.md | 4 ++++ R/add_dockerfiles_renv.R | 23 ++++++++-------------- R/utils.R | 42 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/NEWS.md b/NEWS.md index d9ccf69c..e94bc37b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,9 @@ # 0.3.5.9000+ (dev version) + +add_dockerfile_with_renv now works well with uppercase in package name + ## Soft deprecated ## Hard deprecated @@ -30,6 +33,7 @@ ## Internal changes + # golem 0.3.5 Update in the tests for CRAN (commented a test that made new version of testthat fail). diff --git a/R/add_dockerfiles_renv.R b/R/add_dockerfiles_renv.R index bed36cfa..8e146487 100644 --- a/R/add_dockerfiles_renv.R +++ b/R/add_dockerfiles_renv.R @@ -37,13 +37,9 @@ add_dockerfile_with_renv_ <- function( ) } - fs_file_copy( - path = lockfile, - new_path = output_dir, - overwrite = TRUE - ) + file.copy(from = lockfile, to = output_dir) + socle <- dockerfiler::dock_from_renv( - socle <- dockerfiler_dock_from_renv( lockfile = lockfile, distro = distro, FROM = FROM, @@ -56,12 +52,9 @@ add_dockerfile_with_renv_ <- function( socle$write(as = file.path(output_dir, "Dockerfile_base")) - my_dock <- dockerfiler_Dockerfile()$new( - FROM = paste0( - golem::get_golem_name(), - "_base" - ) - ) + + my_dock <- dockerfiler::Dockerfile$new(FROM = tolower(paste0(golem::get_golem_name(), "_base"))) + my_dock$COPY("renv.lock.prod", "renv.lock") @@ -186,11 +179,11 @@ add_dockerfile_with_renv <- function( docker build -f Dockerfile --progress=plain -t %s . docker run -p %s:%s %s # then go to 127.0.0.1:%s", - paste0(golem::get_golem_name(), "_base"), - paste0(golem::get_golem_name(), ":latest"), + tolower(paste0(golem::get_golem_name(), "_base")), + tolower( paste0(golem::get_golem_name(), ":latest")), port, port, - paste0(golem::get_golem_name(), ":latest"), + tolower(paste0(golem::get_golem_name(), ":latest")), port ) diff --git a/R/utils.R b/R/utils.R index a461e9a9..4b021a16 100644 --- a/R/utils.R +++ b/R/utils.R @@ -414,6 +414,48 @@ yesno <- function(...) { menu(c("Yes", "No")) == 1 } + +# Checking that a package is installed +check_is_installed <- function( + pak, + ... +) { + if ( + !requireNamespace(pak, ..., quietly = TRUE) + ) { + stop( + sprintf( + "The {%s} package is required to run this function.\nYou can install it with `install.packages('%s')`.", + pak, + pak + ), + call. = FALSE + ) + } +} + +required_version <- function( + pak, + version +) { + if ( + utils::packageVersion(pak) < version + ) { + stop( + sprintf( + "This function require the version '%s' of the {%s} package.\nYou can update with `install.packages('%s')`.", + version, + pak, + pak + ), + call. = FALSE + ) + } +} + + + + add_sass_code <- function(where, dir, name) { if (fs_file_exists(where)) { if (fs_file_exists("dev/run_dev.R")) { From 5c756186fe02b8ad1ee3fcfc09c2e2928453e91d Mon Sep 17 00:00:00 2001 From: vincent guyader Date: Wed, 7 Dec 2022 15:01:05 +0100 Subject: [PATCH 26/55] fix dev branch (#948) * fix allow pkgload no to be installed * fix document_and_reload rd * chore update NEWS and bump version * fix force repos in test to avoid "trying to use CRAN without setting a mirror" --- DESCRIPTION | 4 ++-- NEWS.md | 5 +---- R/bootstrap_pkgload.R | 5 ++++- tests/testthat/test-install_dev_deps.R | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ac647cab..ac0ed4a3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: golem Title: A Framework for Robust Shiny Applications -Version: 0.3.5.9003 +Version: 0.3.5.9004 Authors@R: c(person(given = "Colin", family = "Fay", @@ -90,4 +90,4 @@ Config/testthat/edition: 3 Encoding: UTF-8 Language: en-US Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.2 diff --git a/NEWS.md b/NEWS.md index e94bc37b..63b3891c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,9 +2,6 @@ # 0.3.5.9000+ (dev version) - -add_dockerfile_with_renv now works well with uppercase in package name - ## Soft deprecated ## Hard deprecated @@ -29,7 +26,7 @@ add_dockerfile_with_renv now works well with uppercase in package name + The setting of the config file has been unified so that we are sure to keep the !expr in `golem_set_wd()`, and the codebase has been simplified for this (#709). + The functions adding files can no longer take a `name` argument that has length() > 1. This used to cause some bugs (#781) + The typo in `install.packages()` in 02_dev.R has been corrected (@asiripanich) - ++ `add_dockerfile_with_renv()` now works well with uppercase in package name ## Internal changes diff --git a/R/bootstrap_pkgload.R b/R/bootstrap_pkgload.R index c2666a5a..7429f31b 100644 --- a/R/bootstrap_pkgload.R +++ b/R/bootstrap_pkgload.R @@ -7,7 +7,7 @@ check_pkgload_installed <- function() { ) } -uses_testthat <- getFromNamespace("uses_testthat", "pkgload") + pkgload_load_all <- function( @@ -24,6 +24,9 @@ pkgload_load_all <- function( warn_conflicts = TRUE ) { check_roxygen2_installed() + check_pkgload_installed() + + uses_testthat <- getFromNamespace("uses_testthat", "pkgload") pkgload::load_all( path = path, reset = reset, diff --git a/tests/testthat/test-install_dev_deps.R b/tests/testthat/test-install_dev_deps.R index 8baa1047..8eebb5fb 100644 --- a/tests/testthat/test-install_dev_deps.R +++ b/tests/testthat/test-install_dev_deps.R @@ -1,6 +1,7 @@ test_that("install_dev_deps works", { install_dev_deps( - force_install = TRUE + force_install = TRUE, + repos = "https://cran.rstudio.com" ) paks <- unique( c( From 63ac8523ba48af432b129c421e1595807e487177 Mon Sep 17 00:00:00 2001 From: vincent guyader Date: Fri, 9 Dec 2022 13:39:49 +0100 Subject: [PATCH 27/55] draft : 950 without cli (#951) * remove cli and crayon from hard deps --- DESCRIPTION | 60 +++++++-------------- NAMESPACE | 4 -- NEWS.md | 2 +- R/add_dockerfiles.R | 12 ++--- R/add_files.R | 2 - R/add_rstudio_files.R | 5 +- R/boostrap_cli.R | 38 ++++++++++++++ R/boostrap_crayon.R | 15 ++++++ R/browser_button.R | 26 ++++----- R/create_golem.R | 17 +++--- R/desc.R | 3 +- R/disable_autoload.R | 2 +- R/enable_roxygenize.R | 4 +- R/golem-yaml-utils.R | 2 +- R/install_dev_deps.R | 19 +++---- R/modules_fn.R | 1 - R/reload.R | 4 +- R/set_golem_options.R | 4 +- R/use_favicon.R | 2 +- R/use_files.R | 1 - R/use_utils.R | 1 - R/utils.R | 93 ++++++--------------------------- _pkgdown.yml | 14 +++-- vignettes/f_extending_golem.Rmd | 4 +- 24 files changed, 147 insertions(+), 188 deletions(-) create mode 100644 R/boostrap_cli.R create mode 100644 R/boostrap_crayon.R diff --git a/DESCRIPTION b/DESCRIPTION index ac0ed4a3..5c5fcc07 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,45 +1,21 @@ Package: golem Title: A Framework for Robust Shiny Applications -Version: 0.3.5.9004 -Authors@R: - c(person(given = "Colin", - family = "Fay", - role = c("cre", "aut"), - email = "contact@colinfay.me", - comment = c(ORCID = "0000-0001-7343-1846")), - person(given = "Vincent", - family = "Guyader", - role = "aut", - email = "vincent@thinkr.fr", - comment = c(ORCID = "0000-0003-0671-9270", "previous maintainer")), - person(given = "Sébastien", - family = "Rochette", - role = "aut", - email = "sebastien@thinkr.fr", - comment = c(ORCID = "0000-0002-1565-9313")), - person(given = "Cervan", - family = "Girard", - role = "aut", - email = "cervan@thinkr.fr", - comment = c(ORCID = "0000-0002-4816-4624")), - person(given = "Novica", - family = "Nakov", - role = "ctb", - email = "nnovica@gmail.com"), - person(given = "David", - family = "Granjon", - role = "ctb", - email = "dgranjon@ymail.com"), - person(given = "Arthur", - family = "Bréant", - role = "ctb", - email = "arthur@thinkr.fr"), - person(given = "Antoine", - family = "Languillaume", - role = "ctb", - email = "antoine@thinkr.fr"), - person(given = "ThinkR", - role = "cph")) +Version: 0.3.5.9005 +Authors@R: c( + person("Colin", "Fay", , "contact@colinfay.me", role = c("cre", "aut"), + comment = c(ORCID = "0000-0001-7343-1846")), + person("Vincent", "Guyader", , "vincent@thinkr.fr", role = "aut", + comment = c(ORCID = "0000-0003-0671-9270", "previous maintainer")), + person("Sébastien", "Rochette", , "sebastien@thinkr.fr", role = "aut", + comment = c(ORCID = "0000-0002-1565-9313")), + person("Cervan", "Girard", , "cervan@thinkr.fr", role = "aut", + comment = c(ORCID = "0000-0002-4816-4624")), + person("Novica", "Nakov", , "nnovica@gmail.com", role = "ctb"), + person("David", "Granjon", , "dgranjon@ymail.com", role = "ctb"), + person("Arthur", "Bréant", , "arthur@thinkr.fr", role = "ctb"), + person("Antoine", "Languillaume", , "antoine@thinkr.fr", role = "ctb"), + person("ThinkR", role = "cph") + ) Description: An opinionated framework for building a production-ready 'Shiny' application. This package contains a series of tools for building a robust 'Shiny' application from start to finish. @@ -50,9 +26,7 @@ Depends: R (>= 3.0) Imports: attempt (>= 0.3.0), - cli (>= 2.0.0), config, - crayon, here, htmltools, rlang (>= 1.0.0), @@ -62,6 +36,8 @@ Imports: yaml Suggests: covr, + cli (>= 2.0.0), + crayon, devtools, dockerfiler (>= 0.2.0), knitr, diff --git a/NAMESPACE b/NAMESPACE index 6848cce5..de7f62cb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -92,10 +92,6 @@ importFrom(attempt,is_try_error) importFrom(attempt,stop_if) importFrom(attempt,stop_if_not) importFrom(attempt,without_warning) -importFrom(cli,cat_bullet) -importFrom(cli,cat_line) -importFrom(cli,cat_rule) -importFrom(cli,cli_alert_info) importFrom(config,get) importFrom(htmltools,htmlDependency) importFrom(rstudioapi,documentSaveAll) diff --git a/NEWS.md b/NEWS.md index 63b3891c..b565d0e9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,7 +12,7 @@ ## New features / user visible changes -+ The following hard dependencies have been moved to soft dependencies, as you'll only need them while developing: `{pkgload}`, `{roxygen2}`, `{fs}`, `{usethis}` ++ The following hard dependencies have been moved to soft dependencies, as you'll only need them while developing: `{pkgload}`, `{roxygen2}`, `{fs}`, `{usethis}`, `{cli}`, `{crayon}` + Soft dependency check is now done via `rlang::check_installed()` (#835) + `golem::run_dev()` has been refactored to match the behavior of other functions, notably it now uses `golem::get_golem_wd()` to find the current working dir. + `{golem}` now depends on `{rlang}` version >= 1.0.0 diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index b5632c95..bb1e915a 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -388,18 +388,18 @@ add_dockerfile_heroku_ <- talk_once( ) ) - cat_rule("From your command line, run:") - cat_line("heroku container:login") - cat_line( + cli_cat_rule("From your command line, run:") + cli_cat_line("heroku container:login") + cli_cat_line( sprintf("heroku create %s", apps_h) ) - cat_line( + cli_cat_line( sprintf("heroku container:push web --app %s", apps_h) ) - cat_line( + cli_cat_line( sprintf("heroku container:release web --app %s", apps_h) ) - cat_line( + cli_cat_line( sprintf("heroku open --app %s", apps_h) ) cat_red_bullet("Be sure to have the heroku CLI installed.") diff --git a/R/add_files.R b/R/add_files.R index 1b964d21..663cdd2d 100644 --- a/R/add_files.R +++ b/R/add_files.R @@ -22,7 +22,6 @@ #' @export #' @rdname add_files #' @importFrom attempt stop_if -#' @importFrom cli cat_bullet #' @importFrom utils file.edit #' #' @note `add_ui_server_files` will be deprecated in future version of `{golem}` @@ -452,7 +451,6 @@ add_css_file <- function( #' @export #' @rdname add_files -#' @importFrom cli cli_alert_info add_sass_file <- function( name, pkg = get_golem_wd(), diff --git a/R/add_rstudio_files.R b/R/add_rstudio_files.R index 44955959..50631f0b 100644 --- a/R/add_rstudio_files.R +++ b/R/add_rstudio_files.R @@ -1,5 +1,4 @@ #' @importFrom utils capture.output -#' @importFrom cli cat_bullet add_rstudio_files <- function( pkg, open, @@ -47,8 +46,8 @@ add_rstudio_files <- function( usethis_use_package("pkgload") cat_created(where) - cat_line("To deploy, run:") - cat_bullet(darkgrey("rsconnect::deployApp()\n")) + cli_cat_line("To deploy, run:") + cli_cat_bullet(crayon_darkgrey("rsconnect::deployApp()\n")) cat_red_bullet( sprintf( "Note that you'll need to upload the whole package to %s", diff --git a/R/boostrap_cli.R b/R/boostrap_cli.R new file mode 100644 index 00000000..c9f6da44 --- /dev/null +++ b/R/boostrap_cli.R @@ -0,0 +1,38 @@ +# All the fns here check that {cli} is installed +# before doing anything. +check_cli_installed <- function(reason = "to have attractive command line interfaces with {golem}.\nYou can install all {golem} dev dependencies with `golem::install_dev_deps()`.") { + rlang::check_installed( + "cli", + version = "2.0.0", + reason = reason + ) +} + +cli_cat_bullet <- function(...) { + check_cli_installed() + cli::cat_bullet(...) +} + + +cli_cat_line <- function(...) { + check_cli_installed() + + do_if_unquiet({ + cli::cat_line(...) + }) +} + +cli_cat_rule <- function(...) { + check_cli_installed() + + do_if_unquiet({ + cli::cat_rule( + ... + ) + }) + + +} + + + diff --git a/R/boostrap_crayon.R b/R/boostrap_crayon.R new file mode 100644 index 00000000..dda3a842 --- /dev/null +++ b/R/boostrap_crayon.R @@ -0,0 +1,15 @@ +# All the fns here check that {cli} is installed +# before doing anything. +check_crayon_installed <- function(reason = "to have attractive command line interfaces with {golem}.\nYou can install all {golem} dev dependencies with `golem::install_dev_deps()`.") { + rlang::check_installed( + "crayon", + reason = reason + ) +} + + +# from usethis https://github.com/r-lib/usethis/ +crayon_darkgrey <- function(x) { + check_crayon_installed() + x <- crayon::make_style("darkgrey")(x) +} diff --git a/R/browser_button.R b/R/browser_button.R index 55e11776..4e3bff4c 100644 --- a/R/browser_button.R +++ b/R/browser_button.R @@ -6,18 +6,18 @@ #' Prints the code to the console. #' @export #' -#' @importFrom cli cat_rule cat_line + browser_button <- function() { - cat_rule("To be copied in your UI") - cat_line(darkgrey('actionButton("browser", "browser"),')) - cat_line(darkgrey('tags$script("$(\'#browser\').hide();")')) - cat_line() - cat_rule("To be copied in your server") - cat_line(darkgrey("observeEvent(input$browser,{")) - cat_line(darkgrey(" browser()")) - cat_line(darkgrey("})")) - cat_line() - cat_line("By default, this button will be hidden.") - cat_line("To show it, open your web browser JavaScript console") - cat_line("And run $('#browser').show();") + cli_cat_rule("To be copied in your UI") + cli_cat_line(crayon_darkgrey('actionButton("browser", "browser"),')) + cli_cat_line(crayon_darkgrey('tags$script("$(\'#browser\').hide();")')) + cli_cat_line() + cli_cat_rule("To be copied in your server") + cli_cat_line(crayon_darkgrey("observeEvent(input$browser,{")) + cli_cat_line(crayon_darkgrey(" browser()")) + cli_cat_line(crayon_darkgrey("})")) + cli_cat_line() + cli_cat_line("By default, this button will be hidden.") + cli_cat_line("To show it, open your web browser JavaScript console") + cli_cat_line("And run $('#browser').show();") } diff --git a/R/create_golem.R b/R/create_golem.R index 3c8a6f04..76d421e3 100644 --- a/R/create_golem.R +++ b/R/create_golem.R @@ -54,7 +54,6 @@ replace_package_name <- function( #' For compatibility issue, this function turns `options(shiny.autoload.r)` #' to `FALSE`. See https://github.com/ThinkR-open/golem/issues/468 for more background. #' -#' @importFrom cli cat_rule cat_line #' @importFrom utils getFromNamespace #' @importFrom rstudioapi isAvailable openProject hasFun #' @importFrom yaml write_yaml @@ -79,7 +78,7 @@ create_golem <- function( ) if (check_name) { - cat_rule("Checking package name") + cli_cat_rule("Checking package name") rlang::check_installed( "usethis", version = "1.6.0", @@ -108,7 +107,7 @@ create_golem <- function( cat_red_bullet("Overwriting existing project.") } } else { - cat_rule("Creating dir") + cli_cat_rule("Creating dir") usethis_create_project( path = path_to_golem, open = FALSE @@ -120,7 +119,7 @@ create_golem <- function( } - cat_rule("Copying package skeleton") + cli_cat_rule("Copying package skeleton") from <- golem_sys("shinyexample") # Copy over whole directory @@ -148,7 +147,7 @@ create_golem <- function( old <- setwd(path_to_golem) - cat_rule("Running project hook function") + cli_cat_rule("Running project hook function") # TODO fix # for some weird reason test() fails here when using golem::create_golem @@ -182,7 +181,7 @@ create_golem <- function( if (isTRUE(with_git)) { - cat_rule("Initializing git repository") + cli_cat_rule("Initializing git repository") git_output <- system( command = paste("git init", path_to_golem), ignore.stdout = TRUE, @@ -205,7 +204,7 @@ create_golem <- function( usethis_use_latest_dependencies() # No .Rprofile for now - # cat_rule("Appending .Rprofile") + # cli_cat_rule("Appending .Rprofile") # write("# Sourcing user .Rprofile if it exists ", ".Rprofile", append = TRUE) # write("home_profile <- file.path(", ".Rprofile", append = TRUE) # write(" Sys.getenv(\"HOME\"), ", ".Rprofile", append = TRUE) @@ -222,9 +221,9 @@ create_golem <- function( setwd(old) - cat_rule("Done") + cli_cat_rule("Done") - cat_line( + cli_cat_line( paste0( "A new golem named ", package_name, diff --git a/R/desc.R b/R/desc.R index 074ca81b..c939c4a2 100644 --- a/R/desc.R +++ b/R/desc.R @@ -11,7 +11,6 @@ #' @param pkg_version The version of the package. Default is 0.0.0.9000 #' @param pkg Path to look for the DESCRIPTION. Default is `get_golem_wd()`. #' -#' @importFrom cli cat_bullet #' #' @export #' @@ -108,7 +107,7 @@ fill_desc <- function( file = "DESCRIPTION" ) - cat_bullet( + cli_cat_bullet( "DESCRIPTION file modified", bullet = "tick", bullet_col = "green" diff --git a/R/disable_autoload.R b/R/disable_autoload.R index a984b02c..9414ada2 100644 --- a/R/disable_autoload.R +++ b/R/disable_autoload.R @@ -20,7 +20,7 @@ disable_autoload <- function(pkg = get_golem_wd()) { "_disable_autoload.R already exists, skipping its creation." ) } else { - cat_rule("Creating _disable_autoload.R") + cli_cat_rule("Creating _disable_autoload.R") write( "# Disabling shiny autoload\n\n# See ?shiny::loadSupport for more information", fls diff --git a/R/enable_roxygenize.R b/R/enable_roxygenize.R index de76ac87..46173661 100644 --- a/R/enable_roxygenize.R +++ b/R/enable_roxygenize.R @@ -8,13 +8,13 @@ enable_roxygenize <- function(path = list.files( pattern = "Rproj$", full.names = TRUE )[1]) { - cat_bullet( + cli_cat_bullet( sprintf("Reading %s content ", basename(path)), bullet = "info", bullet_col = "green" ) source <- yaml::read_yaml(file = path) - cat_bullet( + cli_cat_bullet( "Enable roxygen2", bullet = "info", bullet_col = "green" diff --git a/R/golem-yaml-utils.R b/R/golem-yaml-utils.R index a6f61463..fe495cef 100644 --- a/R/golem-yaml-utils.R +++ b/R/golem-yaml-utils.R @@ -94,7 +94,7 @@ amend_golem_config <- function( if (key == "golem_wd") { cat_if_talk( "You can change golem working directory with set_golem_wd('path/to/wd')", - fun = cat_line + fun = cli_cat_line ) } diff --git a/R/install_dev_deps.R b/R/install_dev_deps.R index 80c05476..0ab4b48d 100644 --- a/R/install_dev_deps.R +++ b/R/install_dev_deps.R @@ -62,21 +62,22 @@ install_dev_deps <- function( for ( pak in unique( c( - "usethis", - "pkgload", - "dockerfiler", - "devtools", - "roxygen2", "attachment", - "rstudioapi", - "here", - "fs", + "cli", + "crayon", "desc", + "devtools", + "dockerfiler", + "fs", + "here", "pkgbuild", + "pkgload", "processx", + "roxygen2", "rsconnect", + "rstudioapi", "testthat", - "rstudioapi" + "usethis" ) ) ) { diff --git a/R/modules_fn.R b/R/modules_fn.R index 1476f12a..9ef1cf34 100644 --- a/R/modules_fn.R +++ b/R/modules_fn.R @@ -19,7 +19,6 @@ #' @note This function will prefix the `name` argument with `mod_`. #' #' @export -#' @importFrom cli cat_bullet #' @importFrom utils file.edit #' #' @seealso [module_template()] diff --git a/R/reload.R b/R/reload.R index 759a9a48..0eb2e150 100644 --- a/R/reload.R +++ b/R/reload.R @@ -119,7 +119,7 @@ document_and_reload <- function( ) }) if (attempt::is_try_error(roxed)) { - cat_rule( + cli_cat_rule( "Error documenting your package" ) dialog_if_has("Alert", "Error documenting your package") @@ -136,7 +136,7 @@ document_and_reload <- function( }) if (attempt::is_try_error(loaded)) { - cat_rule( + cli_cat_rule( "Error loading your package" ) dialog_if_has("Alert", "Error loading your package") diff --git a/R/set_golem_options.R b/R/set_golem_options.R index 2a965ae9..fce0c411 100644 --- a/R/set_golem_options.R +++ b/R/set_golem_options.R @@ -48,7 +48,7 @@ set_golem_options <- function( # golem_install_dev_pkg() function if (talkative) { - cat_rule( + cli_cat_rule( "Setting {golem} options in `golem-config.yml`" ) } @@ -90,7 +90,7 @@ set_golem_options <- function( # This part is for {usethis} and {here} if (talkative) { - cat_rule( + cli_cat_rule( "Setting {usethis} project as `golem_wd`" ) } diff --git a/R/use_favicon.R b/R/use_favicon.R index 6ad5a7e7..1ffd3743 100644 --- a/R/use_favicon.R +++ b/R/use_favicon.R @@ -100,7 +100,7 @@ use_favicon <- function( "You choose a png favicon, please add `ext = 'png'` to `favicon()` within the `golem_add_external_resources()` function in 'app_ui.R'." ) } else { - cat_line( + cli_cat_line( "Favicon is automatically linked in app_ui via `golem_add_external_resources()`" ) } diff --git a/R/use_files.R b/R/use_files.R index f1d479a0..1c322f5d 100644 --- a/R/use_files.R +++ b/R/use_files.R @@ -14,7 +14,6 @@ #' #' @export #' @rdname use_files -#' @importFrom cli cat_bullet #' #' @return The path to the file, invisibly. use_external_js_file <- function( diff --git a/R/use_utils.R b/R/use_utils.R index d004b5e1..f54f786e 100644 --- a/R/use_utils.R +++ b/R/use_utils.R @@ -10,7 +10,6 @@ #' @export #' @rdname utils_files #' -#' @importFrom cli cat_bullet #' @importFrom utils capture.output #' #' @return Used for side-effects. diff --git a/R/utils.R b/R/utils.R index 4b021a16..497a4551 100644 --- a/R/utils.R +++ b/R/utils.R @@ -11,10 +11,7 @@ golem_sys <- function( ) } -# from usethis https://github.com/r-lib/usethis/ -darkgrey <- function(x) { - x <- crayon::make_style("darkgrey")(x) -} + create_if_needed <- function( path, @@ -111,10 +108,9 @@ remove_comments <- function(file) { writeLines(text = lines_without_comment, con = file) } -#' @importFrom cli cat_bullet cat_green_tick <- function(...) { do_if_unquiet({ - cat_bullet( + cli_cat_bullet( ..., bullet = "tick", bullet_col = "green" @@ -122,10 +118,9 @@ cat_green_tick <- function(...) { }) } -#' @importFrom cli cat_bullet cat_red_bullet <- function(...) { do_if_unquiet({ - cli::cat_bullet( + cli_cat_bullet( ..., bullet = "bullet", bullet_col = "red" @@ -133,10 +128,9 @@ cat_red_bullet <- function(...) { }) } -#' @importFrom cli cat_bullet cat_info <- function(...) { do_if_unquiet({ - cli::cat_bullet( + cli_cat_bullet( ..., bullet = "arrow_right", bullet_col = "grey" @@ -144,21 +138,6 @@ cat_info <- function(...) { }) } -cat_rule <- function(...) { - do_if_unquiet({ - cli::cat_rule( - ... - ) - }) -} - -cat_line <- function(...) { - do_if_unquiet({ - cli::cat_line( - ... - ) - }) -} cat_exists <- function(where) { cat_red_bullet( @@ -183,8 +162,8 @@ cat_dir_necessary <- function() { cat_start_download <- function() { do_if_unquiet({ - cat_line("") - cat_rule("Initiating file download") + cli_cat_line("") + cli_cat_line("Initiating file download") }) } @@ -203,8 +182,8 @@ cat_downloaded <- function( cat_start_copy <- function() { do_if_unquiet({ - cat_line("") - cat_rule("Copying file") + cli_cat_line("") + cli_cat_line("Copying file") }) } @@ -341,13 +320,13 @@ after_creation_message_html_template <- function( name ) { do_if_unquiet({ - cat_line("") - cat_rule("To use this html file as a template, add the following code in your UI:") - cat_line(darkgrey("htmlTemplate(")) - cat_line(darkgrey(sprintf(' app_sys("app/www/%s.html"),', file_path_sans_ext(name)))) - cat_line(darkgrey(" body = tagList()")) - cat_line(darkgrey(" # add here other template arguments")) - cat_line(darkgrey(")")) + cli_cat_line("") + cli_cat_line("To use this html file as a template, add the following code in your UI:") + cli_cat_line(crayon_darkgrey("htmlTemplate(")) + cli_cat_line(crayon_darkgrey(sprintf(' app_sys("app/www/%s.html"),', file_path_sans_ext(name)))) + cli_cat_line(crayon_darkgrey(" body = tagList()")) + cli_cat_line(crayon_darkgrey(" # add here other template arguments")) + cli_cat_line(crayon_darkgrey(")")) }) } @@ -414,48 +393,6 @@ yesno <- function(...) { menu(c("Yes", "No")) == 1 } - -# Checking that a package is installed -check_is_installed <- function( - pak, - ... -) { - if ( - !requireNamespace(pak, ..., quietly = TRUE) - ) { - stop( - sprintf( - "The {%s} package is required to run this function.\nYou can install it with `install.packages('%s')`.", - pak, - pak - ), - call. = FALSE - ) - } -} - -required_version <- function( - pak, - version -) { - if ( - utils::packageVersion(pak) < version - ) { - stop( - sprintf( - "This function require the version '%s' of the {%s} package.\nYou can update with `install.packages('%s')`.", - version, - pak, - pak - ), - call. = FALSE - ) - } -} - - - - add_sass_code <- function(where, dir, name) { if (fs_file_exists(where)) { if (fs_file_exists("dev/run_dev.R")) { diff --git a/_pkgdown.yml b/_pkgdown.yml index a2345294..4bac04b8 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -25,7 +25,7 @@ reference: - title: Create a Dockerfile desc: | - Build a container containing your Shiny App. `add_dockerfile()` creates a "classical" Dockerfile, + Build a container containing your Shiny App. `add_dockerfile()` creates a "classical" Dockerfile, while `add_dockerfile_shinyproxy()` and `add_dockerfile_heroku()` creates platform specific Dockerfile. contents: - add_dockerfile @@ -34,7 +34,7 @@ reference: - title: Use files desc: | - `use_external_js_file` and `use_external_css_file`download files from external sources and install + `use_external_js_file` and `use_external_css_file`download files from external sources and install them inside the appropriate directory. `use_utils_ui` copies the golem_utils_ui.R to the R folder and `use_utils_server` copies the golem_utils_server.R to the R folder. contents: @@ -88,7 +88,7 @@ reference: - title: Addins desc: | - `insert_ns()` takes a selected character vector and wrap it in `ns()`. The series of `go_to_*()` + `insert_ns()` takes a selected character vector and wrap it in `ns()`. The series of `go_to_*()` addins help you go to common files used in developing a {golem} application. contents: - insert_ns @@ -102,7 +102,7 @@ reference: - title: JavaScript interaction functions desc: | - `activate_js` is used in your UI to insert directly the JavaScript functions contained in golem. + `activate_js` is used in your UI to insert directly the JavaScript functions contained in golem. These functions can be called from the server with `invoke_js`. `invoke_js` can also be used to launch any JS function created inside a Shiny JavaScript handler. contents: @@ -111,7 +111,7 @@ reference: - title: Options desc: | - Set and get a series of options to be used with `{golem}`. These options are found inside the + Set and get a series of options to be used with `{golem}`. These options are found inside the `golem-config.yml` file, found in most cases inside the inst folder. contents: - set_golem_options @@ -126,9 +126,11 @@ reference: desc: | `use_recommended_deps` adds shiny, DT, attempt, glue, golem, htmltools to dependencies `use_recommended_tests` adds a test folder and copy the golem tests + `install_dev_deps` install all packages needed for golem developpement contents: - use_recommended_deps - use_recommended_tests + - install_dev_deps - title: Misc contents: @@ -157,3 +159,5 @@ reference: - sanity_check - js_handler_template - use_module_test + - get_current_config + - pkg_name diff --git a/vignettes/f_extending_golem.Rmd b/vignettes/f_extending_golem.Rmd index bb623ca5..3c8db429 100644 --- a/vignettes/f_extending_golem.Rmd +++ b/vignettes/f_extending_golem.Rmd @@ -92,7 +92,7 @@ new_css <- function(path, package_name, ...) { write_there(" background-color:red;") write_there("}") - cli::cat_bullet("CSS generated") + cli_cat_bullet("CSS generated") } create_golem("ici", project_hook = new_css) @@ -294,4 +294,4 @@ run_app <- function( ) ) } -``` \ No newline at end of file +``` From 5a5ec0b1d0d1c38337e2d28971c06b4b2dedc569 Mon Sep 17 00:00:00 2001 From: vincent guyader Date: Fri, 9 Dec 2022 19:08:29 +0100 Subject: [PATCH 28/55] update maintenance mode (#952) * fix pkgdown * explain maintenance mode --- NEWS.md | 3 +++ R/with_opt.R | 2 +- _pkgdown.yml | 1 + man/maintenance_page.Rd | 3 +++ vignettes/f_extending_golem.Rmd | 17 +++++++++++++---- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index b565d0e9..24ec3fbf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ + Add `add_partial_html_template()` to create a partial html template, with "just" a div and a `{{ }}` (@nathansquan #858). + ## New features / user visible changes + The following hard dependencies have been moved to soft dependencies, as you'll only need them while developing: `{pkgload}`, `{roxygen2}`, `{fs}`, `{usethis}`, `{cli}`, `{crayon}` @@ -19,6 +20,8 @@ + Functions that print to the console are now quiet if `options("golem.quiet" = TRUE)`, #793 + Small documentation update in dockerfile related functions (#939) + `fill_desc()` now allows to set the version (#877) ++ Setting the Environment variable `GOLEM_MAINTENANCE_ACTIVE` to `TRUE` active the maintenance mode of your app + ## Bug fix + The message after htmlTemplate creation now suggests to add in the UI, not only in app_ui.R (#861) diff --git a/R/with_opt.R b/R/with_opt.R index 3b33a40b..c4cbc777 100644 --- a/R/with_opt.R +++ b/R/with_opt.R @@ -123,7 +123,7 @@ get_golem_options <- function(which = NULL) { #' @importFrom shiny htmlTemplate #' #' @return an html_document -#' +#' @details see the vignette \code{vignette("f_extending_golem", package = "golem")} for details. #' @export maintenance_page <- function() { shiny::htmlTemplate( diff --git a/_pkgdown.yml b/_pkgdown.yml index 4bac04b8..0726a74e 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -146,6 +146,7 @@ reference: - fill_desc - make_dev - with_golem_options + - maintenance_page - title: internal contents: diff --git a/man/maintenance_page.Rd b/man/maintenance_page.Rd index 148e3932..42bb5c7f 100644 --- a/man/maintenance_page.Rd +++ b/man/maintenance_page.Rd @@ -12,3 +12,6 @@ an html_document \description{ A default html page for maintenance mode } +\details{ +see the vignette \code{vignette("f_extending_golem", package = "golem")} for details. +} diff --git a/vignettes/f_extending_golem.Rmd b/vignettes/f_extending_golem.Rmd index 3c8db429..24cd694c 100644 --- a/vignettes/f_extending_golem.Rmd +++ b/vignettes/f_extending_golem.Rmd @@ -200,7 +200,7 @@ golem::add_css_file(name = "custom", template = my_tmpl) ## Turn on the maintenance mode -## What it is +### What it is From time to time, you need your application to be unavailbel: database update, API changes, etc. In order to keep your app running but make it unavailable, you can use a __maintenance mode__. @@ -208,7 +208,7 @@ When this maintenance mode is turned on, your application will be paused and a s `{golem}` comes with a default maintenance page, and you can replace it with you own page. -## How to set the maintenance mode +### How to set the maintenance mode The maintenance mode will be turned on whenever the R process detects that the `GOLEM_MAINTENANCE_ACTIVE` environment variable is set to TRUE. @@ -224,16 +224,25 @@ withr::with_envvar( ``` +or + +```{r eval = FALSE} +Sys.setenv("GOLEM_MAINTENANCE_ACTIVE" = TRUE) +golem::run_dev() +``` + + + If you're deploying on Posit Connect, you can set this variable in the setup panel. If in command line, you can also do ``` -export GOLEM_MAINTENANCE_ACTIVE=TRUE && Rscript -e "mypkg::run_app()" +export GOLEM_MAINTENANCE_ACTIVE=TRUE && Rscript -e "mygolem::run_app()" ``` -## The maintenance page +### The maintenance page `{golem}` comes with a default maintenance page, but you can override it and use your own custom page. From ebf86804622b2f0b3b147c4a4c2b578e0439c53c Mon Sep 17 00:00:00 2001 From: vincent guyader Date: Sat, 10 Dec 2022 08:53:07 +0100 Subject: [PATCH 29/55] feat: remove rstudioapi hard dep (#955) * feat: remove rstudioapi hard dep * remove rstudioapi from NAMESPACE Co-authored-by: Colin Fay --- DESCRIPTION | 2 +- NAMESPACE | 8 ------ R/add_dockerfiles.R | 19 +++----------- R/addins.R | 18 +++++++------ R/bootstrap_rstudio_api.R | 54 +++++++++++++++++++++++++++++++++++++++ R/bootstrap_usethis.R | 2 +- R/create_golem.R | 6 +++-- R/reload.R | 18 ++++++++++--- R/sanity_check.R | 5 ++-- 9 files changed, 90 insertions(+), 42 deletions(-) create mode 100644 R/bootstrap_rstudio_api.R diff --git a/DESCRIPTION b/DESCRIPTION index 5c5fcc07..cd1c2471 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,7 +30,6 @@ Imports: here, htmltools, rlang (>= 1.0.0), - rstudioapi, shiny (>= 1.5.0), utils, yaml @@ -59,6 +58,7 @@ Suggests: renv, usethis (>= 1.6.0), fs, + rstudioapi, desc VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index de7f62cb..e7919bb6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -94,14 +94,6 @@ importFrom(attempt,stop_if_not) importFrom(attempt,without_warning) importFrom(config,get) importFrom(htmltools,htmlDependency) -importFrom(rstudioapi,documentSaveAll) -importFrom(rstudioapi,getSourceEditorContext) -importFrom(rstudioapi,hasFun) -importFrom(rstudioapi,isAvailable) -importFrom(rstudioapi,modifyRange) -importFrom(rstudioapi,navigateToFile) -importFrom(rstudioapi,openProject) -importFrom(rstudioapi,sourceMarkers) importFrom(shiny,addResourcePath) importFrom(shiny,getShinyOption) importFrom(shiny,htmlTemplate) diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index bb1e915a..4901aef5 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -47,7 +47,6 @@ talk_once <- function(.f, msg = "") { #' @export #' @rdname dockerfiles #' -#' @importFrom rstudioapi navigateToFile isAvailable hasFun #' #' @examples #' \donttest{ @@ -176,11 +175,7 @@ add_dockerfile_ <- talk_once( dock$write(output) if (open) { - if (rstudioapi::isAvailable() & rstudioapi::hasFun("navigateToFile")) { - rstudioapi::navigateToFile(output) - } else { - try(file.edit(output)) - } + rstudioapi_navigateToFile(output) } alert_build( path = path, @@ -274,11 +269,7 @@ add_dockerfile_shinyproxy_ <- talk_once( dock$write(output) if (open) { - if (rstudioapi::isAvailable() & rstudioapi::hasFun("navigateToFile")) { - rstudioapi::navigateToFile(output) - } else { - try(file.edit(output)) - } + rstudioapi_navigateToFile(output) } alert_build( path, @@ -407,11 +398,7 @@ add_dockerfile_heroku_ <- talk_once( sprintf("You can replace %s with another app name.", apps_h) ) if (open) { - if (rstudioapi::isAvailable() & rstudioapi::hasFun("navigateToFile")) { - rstudioapi::navigateToFile(output) - } else { - try(file.edit(output)) - } + rstudioapi_navigateToFile(output) } usethis_use_build_ignore(files = output) return(invisible(dock)) diff --git a/R/addins.R b/R/addins.R index 50502b9d..442c7353 100644 --- a/R/addins.R +++ b/R/addins.R @@ -4,9 +4,7 @@ #' The series of `go_to_*()` addins help you go to #' common files used in developing a `{golem}` application. #' -#' @importFrom rstudioapi getSourceEditorContext modifyRange #' @importFrom attempt stop_if_not -#' @importFrom rstudioapi modifyRange #' #' @aliases addins #' @rdname addins @@ -17,16 +15,16 @@ NULL #' @aliases addins insert_ns <- function() { stop_if_not( - rstudioapi::hasFun("getSourceEditorContext"), + rstudioapi_hasFun("getSourceEditorContext"), msg = "Your version of RStudio does not support `getSourceEditorContext`" ) stop_if_not( - rstudioapi::hasFun("modifyRange"), + rstudioapi_hasFun("modifyRange"), msg = "Your version of RStudio does not support `modifyRange`" ) - curr_editor <- rstudioapi::getSourceEditorContext() + curr_editor <- rstudioapi_getSourceEditorContext() id <- curr_editor$id sel_rng <- curr_editor$selection[[1]]$range @@ -34,7 +32,11 @@ insert_ns <- function() { mod_text <- paste0("ns(", sel_text, ")") - rstudioapi::modifyRange(sel_rng, mod_text, id = id) + rstudioapi_modifyRange( + sel_rng, + mod_text, + id = id + ) } go_to <- function( @@ -50,11 +52,11 @@ go_to <- function( } stop_if_not( - rstudioapi::hasFun("navigateToFile"), + rstudioapi_hasFun("navigateToFile"), msg = "Your version of RStudio does not support `navigateToFile`" ) - rstudioapi::navigateToFile(file) + rstudioapi_navigateToFile(file) } #' @rdname addins diff --git a/R/bootstrap_rstudio_api.R b/R/bootstrap_rstudio_api.R new file mode 100644 index 00000000..e66901dc --- /dev/null +++ b/R/bootstrap_rstudio_api.R @@ -0,0 +1,54 @@ +check_rstudioapi_installed <- function(reason = "to manipulate RStudio files.") { + rlang::check_installed( + "rstudioapi", + reason = reason + ) +} + + +rstudioapi_navigateToFile <- function(output){ + # Don't suggest to install + if (rlang::is_installed("rstudioapi")){ + if ( + rstudioapi::isAvailable() & + rstudioapi::hasFun("navigateToFile") + ) { + rstudioapi::navigateToFile(output) + } else { + try(file.edit(output)) + } + } else { + try(file.edit(output)) + } + +} + +rstudioapi_hasFun <- function( + fun +){ + # Default to FALSE so that it's FALSE + # If package is not installed + hasFun <- FALSE + if (rlang::is_installed("rstudioapi")){ + hasFun <- rstudioapi::hasFun(fun) + } + hasFun +} + +rstudioapi_getSourceEditorContext <- function(){ + check_rstudioapi_installed() + rstudioapi::getSourceEditorContext() +} + +rstudioapi_modifyRange <- function( + location = NULL, + text = NULL, + id = NULL +){ + check_rstudioapi_installed() + rstudioapi::modifyRange( + location = location, + text = text, + id = id + ) +} diff --git a/R/bootstrap_usethis.R b/R/bootstrap_usethis.R index 1e513da5..1e033f2c 100644 --- a/R/bootstrap_usethis.R +++ b/R/bootstrap_usethis.R @@ -38,7 +38,7 @@ usethis_use_package <- function( usethis_create_project <- function( path, - rstudio = rstudioapi::isAvailable(), + rstudio = rstudioapi::isAvailable(), # rstudioap is usethis Imports, so its ok open = rlang::is_interactive() ) { check_usethis_installed( diff --git a/R/create_golem.R b/R/create_golem.R index 76d421e3..2ec236f4 100644 --- a/R/create_golem.R +++ b/R/create_golem.R @@ -55,7 +55,6 @@ replace_package_name <- function( #' to `FALSE`. See https://github.com/ThinkR-open/golem/issues/468 for more background. #' #' @importFrom utils getFromNamespace -#' @importFrom rstudioapi isAvailable openProject hasFun #' @importFrom yaml write_yaml #' #' @export @@ -236,7 +235,10 @@ create_golem <- function( if (isTRUE(open)) { - if (rstudioapi::isAvailable() & rstudioapi::hasFun("openProject")) { + if ( + rlang::is_installed("rstudioapi") && + rstudioapi::isAvailable() && rstudioapi::hasFun("openProject") + ) { rstudioapi::openProject(path = path) } else { setwd(path) diff --git a/R/reload.R b/R/reload.R index 0eb2e150..c92b5d9a 100644 --- a/R/reload.R +++ b/R/reload.R @@ -88,7 +88,6 @@ check_name_consistency <- function(pkg) { #' @inheritParams pkgload::load_all #' #' @param ... Other arguments passed to `pkgload::load_all()` -#' @importFrom rstudioapi isAvailable hasFun documentSaveAll #' @export #' #' @return Used for side-effects @@ -107,7 +106,11 @@ document_and_reload <- function( check_name_consistency(pkg) rlang::check_installed("pkgload") - if (rstudioapi::isAvailable() & rstudioapi::hasFun("documentSaveAll")) { + if ( + rlang::is_installed("rstudioapi") && + rstudioapi::isAvailable() && + rstudioapi::hasFun("documentSaveAll") + ) { rstudioapi::documentSaveAll() } roxed <- try({ @@ -144,8 +147,15 @@ document_and_reload <- function( } } -dialog_if_has <- function(title, message, url = "") { - if (rstudioapi::isAvailable() & rstudioapi::hasFun("showDialog")) { +dialog_if_has <- function( + title, + message, + url = "" +) { + if ( + rlang::is_installed("rstudioapi") && + rstudioapi::isAvailable() && rstudioapi::hasFun("showDialog") + ) { rstudioapi::showDialog(title, message, url) } } diff --git a/R/sanity_check.R b/R/sanity_check.R index 86669ec6..8730e151 100644 --- a/R/sanity_check.R +++ b/R/sanity_check.R @@ -8,7 +8,6 @@ #' @rdname sanity_check #' @export #' -#' @importFrom rstudioapi sourceMarkers hasFun isAvailable #' #' @return A DataFrame if any of the words has been found. sanity_check <- function(pkg = get_golem_wd()) { @@ -41,7 +40,9 @@ sanity_check <- function(pkg = get_golem_wd()) { } if (length(source_markers) > 0) { - if (rstudioapi::isAvailable() & rstudioapi::hasFun("sourceMarkers")) { + if ( + rlang::is_installed("rstudioapi") && rstudioapi::isAvailable() &&rstudioapi::hasFun("sourceMarkers" + )) { rstudioapi::sourceMarkers("sanity_check", markers = source_markers) } return(source_markers) From 135560bef9caae2227c4685c552d973424a64c2f Mon Sep 17 00:00:00 2001 From: vincent guyader Date: Mon, 12 Dec 2022 10:35:09 +0100 Subject: [PATCH 30/55] fix #956 improve get_golem_options doc (#957) * fix #956 improve get_golem_options doc * fix doc * add news --- NEWS.md | 1 + R/with_opt.R | 44 +++++++++++++++++++++++++--------------- man/get_golem_options.Rd | 44 +++++++++++++++++++++++++--------------- 3 files changed, 57 insertions(+), 32 deletions(-) diff --git a/NEWS.md b/NEWS.md index 24ec3fbf..1cc51e33 100644 --- a/NEWS.md +++ b/NEWS.md @@ -30,6 +30,7 @@ + The functions adding files can no longer take a `name` argument that has length() > 1. This used to cause some bugs (#781) + The typo in `install.packages()` in 02_dev.R has been corrected (@asiripanich) + `add_dockerfile_with_renv()` now works well with uppercase in package name ++ improve `get_golem_options()` documentation ## Internal changes diff --git a/R/with_opt.R b/R/with_opt.R index c4cbc777..ce7d71cb 100644 --- a/R/with_opt.R +++ b/R/with_opt.R @@ -77,13 +77,32 @@ with_golem_options <- function( #' #' # Define and use golem_options #' if (interactive()) { -#' # 1. Pass parameters to `run_app` +#' # 1. Pass parameters directly to `run_app` #' -#' # to set default value, edit run_app like this : +#' run_app( title="My Golem App", +#' content = "something" ) +#' +#' # 2. Get the values +#' # 2.1 from the UI side +#' +#' h1(get_golem_options("title")) +#' +#' # 2.2 from the server-side +#' +#' output$param <- renderPrint({ +#' paste("param content = ", get_golem_options("content")) +#' }) +#' +#' output$param_full <- renderPrint({ +#' get_golem_options() # list of all golem options as a list. +#' }) +#' +#' # 3. If needed, to set default value, edit `run_app` like this : #' #' run_app <- function( -#' title = "this", -#' content = "that" +#' title = "this", +#' content = "that", +#' ... #' ) { #' with_golem_options( #' app = shinyApp( @@ -91,21 +110,14 @@ with_golem_options <- function( #' server = app_server #' ), #' golem_opts = list( -#' p1 = p1, -#' p3 = p3 +#' title = title, +#' content = content, +#' ... #' ) #' ) #' } -#' -#' # 2. Get the values from the UI side -#' -#' h1(get_golem_options("title")) -#' -#' # 3. Get the value from the server-side -#' -#' output$param <- renderPrint({ -#' paste("param p2 = ", get_golem_options("p2")) -#' }) +#' +#' #' } #' get_golem_options <- function(which = NULL) { diff --git a/man/get_golem_options.Rd b/man/get_golem_options.Rd index a0e2895f..0eadfabc 100644 --- a/man/get_golem_options.Rd +++ b/man/get_golem_options.Rd @@ -21,13 +21,32 @@ parameters passed to \code{run_app()}. # Define and use golem_options if (interactive()) { - # 1. Pass parameters to `run_app` + # 1. Pass parameters directly to `run_app` - # to set default value, edit run_app like this : + run_app( title="My Golem App", + content = "something" ) + + # 2. Get the values + # 2.1 from the UI side + + h1(get_golem_options("title")) + + # 2.2 from the server-side + + output$param <- renderPrint({ + paste("param content = ", get_golem_options("content")) + }) + + output$param_full <- renderPrint({ + get_golem_options() # list of all golem options as a list. + }) + + # 3. If needed, to set default value, edit `run_app` like this : run_app <- function( - title = "this", - content = "that" + title = "this", + content = "that", + ... ) { with_golem_options( app = shinyApp( @@ -35,21 +54,14 @@ if (interactive()) { server = app_server ), golem_opts = list( - p1 = p1, - p3 = p3 + title = title, + content = content, + ... ) ) } - - # 2. Get the values from the UI side - - h1(get_golem_options("title")) - - # 3. Get the value from the server-side - - output$param <- renderPrint({ - paste("param p2 = ", get_golem_options("p2")) - }) + + } } From e8527de47d332b9a83d209dfeb1a65cd73302928 Mon Sep 17 00:00:00 2001 From: vincent guyader Date: Mon, 12 Dec 2022 10:36:47 +0100 Subject: [PATCH 31/55] fix 958 save all before run_dev.R (#959) * fix 958 save all before run_dev.R * add news --- NEWS.md | 1 + R/run_dev.R | 15 ++++++++++++++- man/run_dev.Rd | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1cc51e33..3066b6ed 100644 --- a/NEWS.md +++ b/NEWS.md @@ -21,6 +21,7 @@ + Small documentation update in dockerfile related functions (#939) + `fill_desc()` now allows to set the version (#877) + Setting the Environment variable `GOLEM_MAINTENANCE_ACTIVE` to `TRUE` active the maintenance mode of your app ++ `golem::run_dev()` now save all open documents before sourcing the `dev/run_dev.R` file ## Bug fix diff --git a/R/run_dev.R b/R/run_dev.R index fd5f2e98..6ee8c25f 100644 --- a/R/run_dev.R +++ b/R/run_dev.R @@ -1,6 +1,7 @@ #' Run run_dev.R #' #' @param file File path to `run_dev.R`. Defaults to `R/run_dev.R`. +#' @param save_all boolean. If TRUE, save all open file before sourcing `file` #' @inheritParams add_module #' #' @export @@ -8,9 +9,21 @@ #' @return Used for side-effect run_dev <- function( file = "dev/run_dev.R", - pkg = get_golem_wd() + pkg = get_golem_wd(), + save_all = TRUE ) { +if (save_all){ + if ( + rlang::is_installed("rstudioapi") && + rstudioapi::isAvailable() && + rstudioapi::hasFun("documentSaveAll") + ) { + rstudioapi::documentSaveAll() + } +} + + # We'll look for the run_dev script in the current dir try_dev <- file.path( pkg, diff --git a/man/run_dev.Rd b/man/run_dev.Rd index 3f12448a..eb25135a 100644 --- a/man/run_dev.Rd +++ b/man/run_dev.Rd @@ -4,12 +4,14 @@ \alias{run_dev} \title{Run run_dev.R} \usage{ -run_dev(file = "dev/run_dev.R", pkg = get_golem_wd()) +run_dev(file = "dev/run_dev.R", pkg = get_golem_wd(), save_all = TRUE) } \arguments{ \item{file}{File path to \code{run_dev.R}. Defaults to \code{R/run_dev.R}.} \item{pkg}{Path to the root of the package. Default is \code{get_golem_wd()}.} + +\item{save_all}{boolean. If TRUE, save all open file before sourcing \code{file}} } \value{ Used for side-effect From 54b38b082228e368297eba84b6bd79d5a17e4693 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 14 Dec 2022 21:38:07 +0100 Subject: [PATCH 32/55] doc: version bump & readme --- DESCRIPTION | 8 ++--- README.Rmd | 5 +-- README.md | 89 ++++++++++++++++++++++++++--------------------------- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cd1c2471..9d73703a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: golem Title: A Framework for Robust Shiny Applications -Version: 0.3.5.9005 +Version: 0.4.0 Authors@R: c( person("Colin", "Fay", , "contact@colinfay.me", role = c("cre", "aut"), comment = c(ORCID = "0000-0001-7343-1846")), @@ -22,9 +22,9 @@ Description: An opinionated framework for building a production-ready License: MIT + file LICENSE URL: https://github.com/ThinkR-open/golem BugReports: https://github.com/ThinkR-open/golem/issues -Depends: +Depends: R (>= 3.0) -Imports: +Imports: attempt (>= 0.3.0), config, here, @@ -60,7 +60,7 @@ Suggests: fs, rstudioapi, desc -VignetteBuilder: +VignetteBuilder: knitr Config/testthat/edition: 3 Encoding: UTF-8 diff --git a/README.Rmd b/README.Rmd index 468a9f85..28555092 100644 --- a/README.Rmd +++ b/README.Rmd @@ -29,6 +29,7 @@ knitr::opts_chunk$set( You're reading the doc about version : ``r as.data.frame(read.dcf("DESCRIPTION"))$Version `` + ## Tool series This package is part of a series of tools for Shiny, which includes: @@ -117,9 +118,9 @@ knitr::include_graphics("https://raw.githubusercontent.com/ThinkR-open/golem/mas ## Step by step guide -See full documentation in the {pkgdown} website: +See full documentation in the {pkgdown} website: -[CRAN] +[CRAN] [dev] diff --git a/README.md b/README.md index d90de195..e70d5dda 100644 --- a/README.md +++ b/README.md @@ -19,69 +19,68 @@ shiny applications. ## About -You’re reading the doc about version : `0.3.4.9002` +You’re reading the doc about version : `0.4.0` ## Tool series This package is part of a series of tools for Shiny, which includes: -- `{golem}` - -- `{shinipsum}` - -- `{fakir}` - -- `{shinysnippets}` - +- `{golem}` - +- `{shinipsum}` - +- `{fakir}` - +- `{shinysnippets}` - ## Resources ### The Book : -- -- [paper version of the book “Engineering Production-Grade Shiny - Apps”](https://www.routledge.com/Engineering-Production-Grade-Shiny-Apps/Fay-Rochette-Guyader-Girard/p/book/9780367466022) +- +- [paper version of the book “Engineering Production-Grade Shiny + Apps”](https://www.routledge.com/Engineering-Production-Grade-Shiny-Apps/Fay-Rochette-Guyader-Girard/p/book/9780367466022) ### Blog posts : *Building Big Shiny Apps* -- Part 1: - -- Part 2: - +- Part 1: + +- Part 2: + [*Make a Fitness App from scratch*](https://towardsdatascience.com/production-grade-r-shiny-with-golem-prototyping-51b03f37c2a9) ### Slide decks -- useR! 2019 : [A Framework for Building Robust & Production Ready - Shiny - Apps](https://github.com/VincentGuyader/user2019/raw/master/golem_Vincent_Guyader_USER!2019.pdf) -- ThinkR x RStudio Roadshow,Paris : [Production-grade Shiny Apps with - {golem}](https://speakerdeck.com/colinfay/production-grade-shiny-apps-with-golem) -- rstudio::conf(2020) : [Production-grade Shiny Apps with - golem](https://speakerdeck.com/colinfay/rstudio-conf-2020-production-grade-shiny-apps-with-golem) -- barcelonar (2019-12-03) : [Engineering Production-Grade Shiny Apps - with - {golem}](https://www.barcelonar.org/presentations/BarcelonaR_Building_Production_Grade_Shiny_Apps_with_golem.pdf) +- useR! 2019 : [A Framework for Building Robust & Production Ready Shiny + Apps](https://github.com/VincentGuyader/user2019/raw/master/golem_Vincent_Guyader_USER!2019.pdf) +- ThinkR x RStudio Roadshow,Paris : [Production-grade Shiny Apps with + {golem}](https://speakerdeck.com/colinfay/production-grade-shiny-apps-with-golem) +- rstudio::conf(2020) : [Production-grade Shiny Apps with + golem](https://speakerdeck.com/colinfay/rstudio-conf-2020-production-grade-shiny-apps-with-golem) +- barcelonar (2019-12-03) : [Engineering Production-Grade Shiny Apps + with + {golem}](https://www.barcelonar.org/presentations/BarcelonaR_Building_Production_Grade_Shiny_Apps_with_golem.pdf) ### Video -- [{golem} and Effective Shiny Development - Methods](https://www.youtube.com/watch?v=OU1-CkSVdTI) -- [Hands-on demonstration of - {golem}](https://www.youtube.com/watch?v=3-p9XLvoJV0) -- useR! 2019 : [A Framework for Building Robust & Production Ready - Shiny Apps](https://youtu.be/tCAan6smrjs) -- 🇫🇷 [Introduction to {golem}](https://youtu.be/6qI4NzxlAFU) -- rstudio::conf(2020) : [Production-grade Shiny Apps with - golem](https://www.rstudio.com/resources/rstudioconf-2020/production-grade-shiny-apps-with-golem/) -- 🇫🇷 Rencontres R 2021 : [Conception d’applications Shiny avec - {golem}](https://www.youtube.com/watch?v=0f5Me1PFGDs) -- 🇫🇷 [Déploiement d’une application {shiny} dans docker avec {renv} et - {golem}](https://www.youtube.com/watch?v=diCG4t76k78) +- [{golem} and Effective Shiny Development + Methods](https://www.youtube.com/watch?v=OU1-CkSVdTI) +- [Hands-on demonstration of + {golem}](https://www.youtube.com/watch?v=3-p9XLvoJV0) +- useR! 2019 : [A Framework for Building Robust & Production Ready Shiny + Apps](https://youtu.be/tCAan6smrjs) +- 🇫🇷 [Introduction to {golem}](https://youtu.be/6qI4NzxlAFU) +- rstudio::conf(2020) : [Production-grade Shiny Apps with + golem](https://www.rstudio.com/resources/rstudioconf-2020/production-grade-shiny-apps-with-golem/) +- 🇫🇷 Rencontres R 2021 : [Conception d’applications Shiny avec + {golem}](https://www.youtube.com/watch?v=0f5Me1PFGDs) +- 🇫🇷 [Déploiement d’une application {shiny} dans docker avec {renv} et + {golem}](https://www.youtube.com/watch?v=diCG4t76k78) ### Cheatsheet -- [{golem} cheatsheet](https://thinkr.fr/golem_cheatsheet_v0.1.pdf) +- [{golem} cheatsheet](https://thinkr.fr/golem_cheatsheet_v0.1.pdf) ### Examples apps @@ -89,26 +88,26 @@ These are examples from the community. Please note that they may not necessarily be written in a canonical fashion and may have been written with different versions of `{golem}` or `{shiny}`. -- -- -- -- +- +- +- +- You can also find apps at: -- -- +- +- ## Installation -- You can install the stable version from CRAN with: +- You can install the stable version from CRAN with: ``` r install.packages("golem") ``` -- You can install the development version from - [GitHub](https://github.com/Thinkr-open/golem) with: +- You can install the development version from + [GitHub](https://github.com/Thinkr-open/golem) with: ``` r # install.packages("remotes") From 08577f4bd13dbf5d37b677035d57da0afa5147bb Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 23 Dec 2022 08:49:32 +0100 Subject: [PATCH 33/55] style: linter --- R/boostrap_cli.R | 5 --- R/bootstrap_desc.R | 36 ++++++++-------- R/bootstrap_rstudio_api.R | 67 ++++++++++++++---------------- R/bundle_resources.R | 6 +-- R/config.R | 1 - R/create_golem.R | 2 +- R/modules_fn.R | 1 - R/reload.R | 6 +-- R/run_dev.R | 21 +++++----- R/sanity_check.R | 3 +- R/set_golem_options.R | 1 - R/with_opt.R | 29 +++++++------ tests/testthat/test-create_golem.R | 2 - vignettes/c_deploy.Rmd | 2 +- vignettes/e_config.Rmd | 2 +- 15 files changed, 84 insertions(+), 100 deletions(-) diff --git a/R/boostrap_cli.R b/R/boostrap_cli.R index c9f6da44..d26cb117 100644 --- a/R/boostrap_cli.R +++ b/R/boostrap_cli.R @@ -30,9 +30,4 @@ cli_cat_rule <- function(...) { ... ) }) - - } - - - diff --git a/R/bootstrap_desc.R b/R/bootstrap_desc.R index a91196df..c9fa0ce9 100644 --- a/R/bootstrap_desc.R +++ b/R/bootstrap_desc.R @@ -1,40 +1,40 @@ # All the fns here check that {desc} is installed # before doing anything. check_desc_installed <- function() { - rlang::check_installed( - "desc", - reason = "to fill DESCRIPTION." - ) + rlang::check_installed( + "desc", + reason = "to fill DESCRIPTION." + ) } desc_description <- function(file) { - check_desc_installed() - desc::description$new( - file = file - ) + check_desc_installed() + desc::description$new( + file = file + ) } desc_get <- function(keys) { - check_desc_installed() - desc::desc_get(keys) + check_desc_installed() + desc::desc_get(keys) } desc_get_version <- function() { - check_desc_installed() - desc::desc_get_version() + check_desc_installed() + desc::desc_get_version() } desc_get_deps <- function(file = NULL) { - check_desc_installed() - desc::desc_get_deps(file) + check_desc_installed() + desc::desc_get_deps(file) } desc_get_field <- function(key) { - check_desc_installed() - desc::desc_get_field(key) + check_desc_installed() + desc::desc_get_field(key) } desc_get_author <- function() { - check_desc_installed() - desc::desc_get_author() + check_desc_installed() + desc::desc_get_author() } diff --git a/R/bootstrap_rstudio_api.R b/R/bootstrap_rstudio_api.R index e66901dc..7aa21fb2 100644 --- a/R/bootstrap_rstudio_api.R +++ b/R/bootstrap_rstudio_api.R @@ -6,49 +6,46 @@ check_rstudioapi_installed <- function(reason = "to manipulate RStudio files.") } -rstudioapi_navigateToFile <- function(output){ - # Don't suggest to install - if (rlang::is_installed("rstudioapi")){ - if ( - rstudioapi::isAvailable() & - rstudioapi::hasFun("navigateToFile") - ) { - rstudioapi::navigateToFile(output) - } else { - try(file.edit(output)) - } +rstudioapi_navigateToFile <- function(output) { + # Don't suggest to install + if (rlang::is_installed("rstudioapi")) { + if ( + rstudioapi::isAvailable() & + rstudioapi::hasFun("navigateToFile") + ) { + rstudioapi::navigateToFile(output) } else { - try(file.edit(output)) + try(file.edit(output)) } - + } else { + try(file.edit(output)) + } } -rstudioapi_hasFun <- function( - fun -){ - # Default to FALSE so that it's FALSE - # If package is not installed - hasFun <- FALSE - if (rlang::is_installed("rstudioapi")){ - hasFun <- rstudioapi::hasFun(fun) - } - hasFun +rstudioapi_hasFun <- function(fun) { + # Default to FALSE so that it's FALSE + # If package is not installed + hasFun <- FALSE + if (rlang::is_installed("rstudioapi")) { + hasFun <- rstudioapi::hasFun(fun) + } + hasFun } -rstudioapi_getSourceEditorContext <- function(){ - check_rstudioapi_installed() - rstudioapi::getSourceEditorContext() +rstudioapi_getSourceEditorContext <- function() { + check_rstudioapi_installed() + rstudioapi::getSourceEditorContext() } rstudioapi_modifyRange <- function( - location = NULL, - text = NULL, - id = NULL -){ + location = NULL, + text = NULL, + id = NULL +) { check_rstudioapi_installed() - rstudioapi::modifyRange( - location = location, - text = text, - id = id - ) + rstudioapi::modifyRange( + location = location, + text = text, + id = id + ) } diff --git a/R/bundle_resources.R b/R/bundle_resources.R index faa2b2d2..8756d708 100644 --- a/R/bundle_resources.R +++ b/R/bundle_resources.R @@ -39,7 +39,7 @@ bundle_resources <- function( ) > 0 ) { res[[ - length(res) + 1 + length(res) + 1 ]] <- htmltools::htmlDependency( name, version, @@ -84,7 +84,7 @@ bundle_resources <- function( for (i in css_nms) { res[[ - length(res) + 1 + length(res) + 1 ]] <- tags$link( href = i, rel = "stylesheet" @@ -95,7 +95,7 @@ bundle_resources <- function( if (with_sparkles) { res[[ - length(res) + 1 + length(res) + 1 ]] <- htmlDependency( "sparkles", version = utils::packageVersion("golem"), diff --git a/R/config.R b/R/config.R index 37df7748..9bd40dc6 100644 --- a/R/config.R +++ b/R/config.R @@ -61,7 +61,6 @@ guess_where_config <- function( #' #' @export get_current_config <- function(path = getwd()) { - # We check wether we can guess where the config file is path_conf <- guess_where_config(path) diff --git a/R/create_golem.R b/R/create_golem.R index 2ec236f4..b450a0eb 100644 --- a/R/create_golem.R +++ b/R/create_golem.R @@ -237,7 +237,7 @@ create_golem <- function( if (isTRUE(open)) { if ( rlang::is_installed("rstudioapi") && - rstudioapi::isAvailable() && rstudioapi::hasFun("openProject") + rstudioapi::isAvailable() && rstudioapi::hasFun("openProject") ) { rstudioapi::openProject(path = path) } else { diff --git a/R/modules_fn.R b/R/modules_fn.R index 9ef1cf34..95a8f8fd 100644 --- a/R/modules_fn.R +++ b/R/modules_fn.R @@ -237,7 +237,6 @@ use_module_test <- function( pkg = get_golem_wd(), open = TRUE ) { - # Remove the extension if any name <- file_path_sans_ext(name) # Remove the "mod_" if any diff --git a/R/reload.R b/R/reload.R index c92b5d9a..cf547347 100644 --- a/R/reload.R +++ b/R/reload.R @@ -108,8 +108,8 @@ document_and_reload <- function( if ( rlang::is_installed("rstudioapi") && - rstudioapi::isAvailable() && - rstudioapi::hasFun("documentSaveAll") + rstudioapi::isAvailable() && + rstudioapi::hasFun("documentSaveAll") ) { rstudioapi::documentSaveAll() } @@ -154,7 +154,7 @@ dialog_if_has <- function( ) { if ( rlang::is_installed("rstudioapi") && - rstudioapi::isAvailable() && rstudioapi::hasFun("showDialog") + rstudioapi::isAvailable() && rstudioapi::hasFun("showDialog") ) { rstudioapi::showDialog(title, message, url) } diff --git a/R/run_dev.R b/R/run_dev.R index 6ee8c25f..2479e8c6 100644 --- a/R/run_dev.R +++ b/R/run_dev.R @@ -12,18 +12,17 @@ run_dev <- function( pkg = get_golem_wd(), save_all = TRUE ) { - -if (save_all){ - if ( - rlang::is_installed("rstudioapi") && - rstudioapi::isAvailable() && - rstudioapi::hasFun("documentSaveAll") - ) { - rstudioapi::documentSaveAll() + if (save_all) { + if ( + rlang::is_installed("rstudioapi") && + rstudioapi::isAvailable() && + rstudioapi::hasFun("documentSaveAll") + ) { + rstudioapi::documentSaveAll() + } } -} - - + + # We'll look for the run_dev script in the current dir try_dev <- file.path( pkg, diff --git a/R/sanity_check.R b/R/sanity_check.R index 8730e151..6d2d5a34 100644 --- a/R/sanity_check.R +++ b/R/sanity_check.R @@ -41,8 +41,7 @@ sanity_check <- function(pkg = get_golem_wd()) { if (length(source_markers) > 0) { if ( - rlang::is_installed("rstudioapi") && rstudioapi::isAvailable() &&rstudioapi::hasFun("sourceMarkers" - )) { + rlang::is_installed("rstudioapi") && rstudioapi::isAvailable() && rstudioapi::hasFun("sourceMarkers")) { rstudioapi::sourceMarkers("sanity_check", markers = source_markers) } return(source_markers) diff --git a/R/set_golem_options.R b/R/set_golem_options.R index fce0c411..e371c731 100644 --- a/R/set_golem_options.R +++ b/R/set_golem_options.R @@ -43,7 +43,6 @@ set_golem_options <- function( talkative = TRUE, config_file = golem::get_current_config(golem_wd) ) { - # TODO here we'll run the # golem_install_dev_pkg() function diff --git a/R/with_opt.R b/R/with_opt.R index ce7d71cb..1ff0acfb 100644 --- a/R/with_opt.R +++ b/R/with_opt.R @@ -19,7 +19,6 @@ with_golem_options <- function( maintenance_page = golem::maintenance_page, print = FALSE ) { - # Check if app is in maintenance if (Sys.getenv("GOLEM_MAINTENANCE_ACTIVE", "FALSE") == "TRUE") { app <- shiny::shinyApp( @@ -79,10 +78,12 @@ with_golem_options <- function( #' if (interactive()) { #' # 1. Pass parameters directly to `run_app` #' -#' run_app( title="My Golem App", -#' content = "something" ) +#' run_app( +#' title = "My Golem App", +#' content = "something" +#' ) #' -#' # 2. Get the values +#' # 2. Get the values #' # 2.1 from the UI side #' #' h1(get_golem_options("title")) @@ -92,17 +93,17 @@ with_golem_options <- function( #' output$param <- renderPrint({ #' paste("param content = ", get_golem_options("content")) #' }) -#' +#' #' output$param_full <- renderPrint({ -#' get_golem_options() # list of all golem options as a list. +#' get_golem_options() # list of all golem options as a list. #' }) -#' +#' #' # 3. If needed, to set default value, edit `run_app` like this : #' #' run_app <- function( -#' title = "this", -#' content = "that", -#' ... +#' title = "this", +#' content = "that", +#' ... #' ) { #' with_golem_options( #' app = shinyApp( @@ -110,14 +111,12 @@ with_golem_options <- function( #' server = app_server #' ), #' golem_opts = list( -#' title = title, -#' content = content, -#' ... +#' title = title, +#' content = content, +#' ... #' ) #' ) #' } -#' -#' #' } #' get_golem_options <- function(which = NULL) { diff --git a/tests/testthat/test-create_golem.R b/tests/testthat/test-create_golem.R index 0dd4a130..92992f06 100644 --- a/tests/testthat/test-create_golem.R +++ b/tests/testthat/test-create_golem.R @@ -2,7 +2,6 @@ ### Helpers functions ---------------------------------------------------------- is_properly_populated_golem <- function(path) { - # All files excepts *.Rproj which changes based on the project name expected_files <- c( "DESCRIPTION", @@ -62,7 +61,6 @@ dummy_dir <- tempfile(pattern = "dummy") dir.create(dummy_dir) withr::with_dir(dummy_dir, { - ## Default test_that("golem is created and properly populated", { dummy_golem_path <- file.path(dummy_dir, "koko") diff --git a/vignettes/c_deploy.Rmd b/vignettes/c_deploy.Rmd index b8d60c07..fd9b1cb0 100644 --- a/vignettes/c_deploy.Rmd +++ b/vignettes/c_deploy.Rmd @@ -160,4 +160,4 @@ deploy/ \-- renv.lock.prod ``` -then follow the README file \ No newline at end of file +then follow the README file diff --git a/vignettes/e_config.Rmd b/vignettes/e_config.Rmd index 4ad83d4d..2ec72636 100644 --- a/vignettes/e_config.Rmd +++ b/vignettes/e_config.Rmd @@ -175,4 +175,4 @@ If you've built an app with `{golem}` before the version 0.2.0, this config file ```{r echo = FALSE} setwd(old) -``` \ No newline at end of file +``` From cf76381a5521e77e17a9a9b93b63afc21b0a0259 Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 23 Dec 2022 08:49:49 +0100 Subject: [PATCH 34/55] styler: linter bis --- R/add_dockerfiles_renv.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/add_dockerfiles_renv.R b/R/add_dockerfiles_renv.R index 8e146487..5d6b18a6 100644 --- a/R/add_dockerfiles_renv.R +++ b/R/add_dockerfiles_renv.R @@ -39,7 +39,6 @@ add_dockerfile_with_renv_ <- function( file.copy(from = lockfile, to = output_dir) socle <- dockerfiler::dock_from_renv( - lockfile = lockfile, distro = distro, FROM = FROM, @@ -180,7 +179,7 @@ docker build -f Dockerfile --progress=plain -t %s . docker run -p %s:%s %s # then go to 127.0.0.1:%s", tolower(paste0(golem::get_golem_name(), "_base")), - tolower( paste0(golem::get_golem_name(), ":latest")), + tolower(paste0(golem::get_golem_name(), ":latest")), port, port, tolower(paste0(golem::get_golem_name(), ":latest")), From 2e394e4ce407ff34023e92910e4023eb8a2f5d7f Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 23 Dec 2022 09:19:43 +0100 Subject: [PATCH 35/55] feat: on create golem, message if dev deps are not installed Issue #915 --- R/create_golem.R | 3 +++ R/install_dev_deps.R | 55 ++++++++++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/R/create_golem.R b/R/create_golem.R index b450a0eb..ad013b04 100644 --- a/R/create_golem.R +++ b/R/create_golem.R @@ -31,6 +31,7 @@ replace_package_name <- function( } + #' Create a package for a Shiny App using `{golem}` #' #' @param path Name of the folder to create the package in. @@ -233,6 +234,8 @@ create_golem <- function( ) ) + check_dev_deps_are_installed() + if (isTRUE(open)) { if ( diff --git a/R/install_dev_deps.R b/R/install_dev_deps.R index 0ab4b48d..1a0926ac 100644 --- a/R/install_dev_deps.R +++ b/R/install_dev_deps.R @@ -60,29 +60,44 @@ install_dev_deps <- function( } for ( - pak in unique( - c( - "attachment", - "cli", - "crayon", - "desc", - "devtools", - "dockerfiler", - "fs", - "here", - "pkgbuild", - "pkgload", - "processx", - "roxygen2", - "rsconnect", - "rstudioapi", - "testthat", - "usethis" - ) - ) + pak in dev_deps ) { if (!rlang::is_installed(pak)) { f(pak, ...) } } } + +dev_deps <- unique( + c( + "attachment", + "cli", + "crayon", + "desc", + "devtools", + "dockerfiler", + "fs", + "here", + "pkgbuild", + "pkgload", + "processx", + "roxygen2", + "rsconnect", + "rstudioapi", + "testthat", + "usethis" + ) +) + +check_dev_deps_are_installed <- function() { + are_installed <- sapply( + dev_deps, + FUN = rlang::is_installed + ) + if (!all(are_installed)) { + message( + "We noticed that some dev dependencies are not installed.", + "You can install them with `install_dev_deps()`." + ) + } +} From 525e97d75ce106449f62623dc6b9922705895c83 Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 23 Dec 2022 09:26:47 +0100 Subject: [PATCH 36/55] doc: entry in news --- NEWS.md | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3066b6ed..1e4de6c7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -> Notes: the # between parenthesis referes to the related issue on GitHub, and the @ refers to an external contributor solving this issue. +> Notes: the # between parenthesis referes to the related issue on GitHub, and the @ refers to an external contributor solving this issue. # 0.3.5.9000+ (dev version) @@ -22,6 +22,7 @@ + `fill_desc()` now allows to set the version (#877) + Setting the Environment variable `GOLEM_MAINTENANCE_ACTIVE` to `TRUE` active the maintenance mode of your app + `golem::run_dev()` now save all open documents before sourcing the `dev/run_dev.R` file ++ When creating an app, you'll get a message if the dev deps are not all installed (#915) ## Bug fix @@ -78,7 +79,7 @@ Update in the tests for CRAN (skip not installed + examples). + `use_code_of_conduct()` in dev script now has the contact param (#812) + All `with_test` params are now TRUE in the dev script (#801) - + + `test-golem-recommended` now has two new tests for `app_sys` and `get_golem_config` (#751) + `use_utils_ui()` `use_utils_server()` & now come with a `with_test` parameter that adds a test file for theses functions (#625 & #801) @@ -88,7 +89,7 @@ Update in the tests for CRAN (skip not installed + examples). + Every `{rstudioapi}` calls is now conditionned by the availabily of this function (#776) + `use_external_*` functions no longer suggest to "Go to" (#713, @novica) - + + `create_golem()` now comes with `with_git` parameter that can be used to initialize git repository while creating a project template + `use_recommended_tests()` now comes with `testServer` (#720). @@ -103,7 +104,7 @@ Update in the tests for CRAN (skip not installed + examples). + run_dev now has `options(shiny.port = httpuv::randomPort())` to prevent the browser from caching the CSS & JS files (#675) -+ You can now specify the path to R in `expect_running()`. ++ You can now specify the path to R in `expect_running()`. ## Bug fix @@ -119,7 +120,7 @@ Update in the tests for CRAN (skip not installed + examples). + Fixed issue with expect_running & path to R (#700, @waiteb5) -+ `expect_running()` now find R.exe on windows. ++ `expect_running()` now find R.exe on windows. + `use_recommended_tests()` no longer add `{processx}` to the `DESCRIPTION` (#710) @@ -171,7 +172,7 @@ Update in the tests for CRAN (skip not installed + examples). + `run_dev()` performs a check on golem name. -+ `sanity_check()` function has been added to check for any 'browser()' or commented #TODO / #TOFIX / #BUG in the code (#1354 @Swechhya) ++ `sanity_check()` function has been added to check for any 'browser()' or commented #TODO / #TOFIX / #BUG in the code (#1354 @Swechhya) ## New features @@ -213,7 +214,7 @@ Update in the tests for CRAN (skip not installed + examples). ## Breaking changes -+ `add_dockerfile*` function now return the `{dockerfiler}` object instead of the path to it. It allows to modify the Dockerfile object programmatically. (#493) ++ `add_dockerfile*` function now return the `{dockerfiler}` object instead of the path to it. It allows to modify the Dockerfile object programmatically. (#493) + The `get_golem_config` now first look for a `GOLEM_CONFIG_ACTIVE` before looking for `R_CONFIG_ACTIVE` (#563) @@ -222,7 +223,7 @@ Update in the tests for CRAN (skip not installed + examples). + `add_` functions no longer append to file if it already exists (#393) + `config::get()` is no longer exported to prevent namespace conflicts with `base::get()` - + + fixed issue with favicon when package is built (#387) + `use_external_*()` function don't add ext if already there (#405) @@ -300,11 +301,11 @@ Update in the tests for CRAN (skip not installed + examples). + `devtools::test()` in 03_deploy.R is now `devtools::check()` -+ modules bow have a placeholder for content ++ modules bow have a placeholder for content + Dev scripts have been rewritten and rerordered a litte bit -## Breaking changes +## Breaking changes + `invoke_js()` now takes a list of elements to send to JS (through `...`) instead of a vector (#155, @zwycl) @@ -352,13 +353,13 @@ Update in the tests for CRAN (skip not installed + examples). # golem 0.1.0 - CRAN release candidate, v2 -## New Functions +## New Functions + `get_golem_wd` allows to print the current golem working directory, and `set_golem_wd` to change it. -## Breaking changes +## Breaking changes -+ In order to work, the functions creating files need a `golem.wd`. This working directory is set by `set_golem_options` or the first time you create a file. It default to `"."`, the current directory. ++ In order to work, the functions creating files need a `golem.wd`. This working directory is set by `set_golem_options` or the first time you create a file. It default to `"."`, the current directory. + Changes in the name of the args in `set_golem_options`: `pkg_path` is now `golem_wd`, `pkg_name` is now `golem_name`, `pkg_version` is now `golem_version` @@ -372,7 +373,7 @@ Update in the tests for CRAN (skip not installed + examples). ## Changes in the way run_app and deploy files are build -+ There is now a unique framework for run_app, that allows to deploy anywhere and can accept arguments. These arguments can then be retrieved with `get_golem_options()`. ++ There is now a unique framework for run_app, that allows to deploy anywhere and can accept arguments. These arguments can then be retrieved with `get_golem_options()`. > See https://rtask.thinkr.fr/blog/shinyapp-runapp-shinyappdir-difference/ @@ -385,7 +386,7 @@ Update in the tests for CRAN (skip not installed + examples). + There is now `add_shinyserver_file` & `add_shinyappsio_file`, #40 + `add_ui_server_files()` creates an ui & server.R files. -## Small functions updates +## Small functions updates + Functions that create file(s) now automatically create folder if it's not there. Can be prevented with `dir_create = FALSE` + Functions that create file(s) can now be prevented from opening with `open = FALSE`, #75 @@ -394,25 +395,25 @@ Update in the tests for CRAN (skip not installed + examples). # golem 0.0.1.6000+ -## Changes +## Changes * `create_golem()` now switch to the newly created project * `use_git()` is not listed in `dev/01_start.R` -## Breaking changes +## Breaking changes * Renamed `add_rconnect_file()` to `add_rstudioconnect_file()` * Renamed `create_shiny_template()` to `create_golem()` * Renamed `js()` to `activate_js()` * Renamed `use_recommended_dep()` to `use_recommended_deps()` -## New functions +## New functions * `invoke_js()` allows to call JS functions from the server side. #52 # golem 0.0.1.5000 -## Changes +## Changes * The dev files are now split in three - start / dev / deploy @@ -444,7 +445,7 @@ Update in the tests for CRAN (skip not installed + examples). * `use_utils_prod` is now included in golem so you don't have to explicitly include the functions. -## Docs +## Docs * Golem now has four vignettes From 2c869d35d63985d7441b6fd0bfe68dc901425ebb Mon Sep 17 00:00:00 2001 From: Stephen Holsenbeck Date: Mon, 19 Dec 2022 17:47:15 -0500 Subject: [PATCH 37/55] Add a demo shinyapps.io snippet for the _03_deploy_ file --- inst/shinyexample/dev/03_deploy.R | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/inst/shinyexample/dev/03_deploy.R b/inst/shinyexample/dev/03_deploy.R index 2f9595ef..a8e3701e 100644 --- a/inst/shinyexample/dev/03_deploy.R +++ b/inst/shinyexample/dev/03_deploy.R @@ -38,3 +38,23 @@ golem::add_dockerfile_with_renv() ## If you want to deploy to ShinyProxy golem::add_dockerfile_with_renv_shinyproxy() +## ShinyApps.io Demo Deployment Snippet +# If you want to deploy to ShinyApps.io without using the built in RStudio workflow +rsconnect::deployApp( + appName = desc::desc_get_field("Package"), + appTitle = desc::desc_get_field("Package"), + appFiles = c( + # Add any additional files unique to your app here. + "R/", + "inst/", + "data/", + "NAMESPACE", + "DESCRIPTION", + "app.R", + ".Rprofile", + ".Renviron" + ), + appId = rsconnect::deployments(".")$appID, + lint = FALSE, + forceUpdate = TRUE +) From 22f346768bbc1928bb6b575fafe1afe889136012 Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 23 Dec 2022 09:49:24 +0100 Subject: [PATCH 38/55] fix: removed the dot file from deployment Issue #923 --- inst/shinyexample/dev/03_deploy.R | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/inst/shinyexample/dev/03_deploy.R b/inst/shinyexample/dev/03_deploy.R index a8e3701e..1f886875 100644 --- a/inst/shinyexample/dev/03_deploy.R +++ b/inst/shinyexample/dev/03_deploy.R @@ -38,8 +38,9 @@ golem::add_dockerfile_with_renv() ## If you want to deploy to ShinyProxy golem::add_dockerfile_with_renv_shinyproxy() -## ShinyApps.io Demo Deployment Snippet -# If you want to deploy to ShinyApps.io without using the built in RStudio workflow + +# Deploy to Posit Connect or ShinyApps.io +# In command line. rsconnect::deployApp( appName = desc::desc_get_field("Package"), appTitle = desc::desc_get_field("Package"), @@ -50,9 +51,7 @@ rsconnect::deployApp( "data/", "NAMESPACE", "DESCRIPTION", - "app.R", - ".Rprofile", - ".Renviron" + "app.R" ), appId = rsconnect::deployments(".")$appID, lint = FALSE, From 9ce91506e55fac4221a5cf2dd6d067001a72b5aa Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 23 Dec 2022 09:53:47 +0100 Subject: [PATCH 39/55] doc: news update --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 1e4de6c7..7e9765e3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -23,6 +23,7 @@ + Setting the Environment variable `GOLEM_MAINTENANCE_ACTIVE` to `TRUE` active the maintenance mode of your app + `golem::run_dev()` now save all open documents before sourcing the `dev/run_dev.R` file + When creating an app, you'll get a message if the dev deps are not all installed (#915) ++ 03_deploy now contains an example of sending the app to PositConnect or Shinyapps.io (#923) ## Bug fix From 85a821132aad08c21da3cdde30f86ea00ad304c1 Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 23 Dec 2022 10:23:26 +0100 Subject: [PATCH 40/55] hotfix: check that all boostrap fns are there #961 --- R/add_dockerfiles_renv.R | 2 +- R/boostrap_cli.R | 4 +++- R/create_golem.R | 3 ++- R/sanity_check.R | 9 +++++++-- R/utils.R | 6 ++---- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/R/add_dockerfiles_renv.R b/R/add_dockerfiles_renv.R index 5d6b18a6..a784db2e 100644 --- a/R/add_dockerfiles_renv.R +++ b/R/add_dockerfiles_renv.R @@ -38,7 +38,7 @@ add_dockerfile_with_renv_ <- function( } file.copy(from = lockfile, to = output_dir) - socle <- dockerfiler::dock_from_renv( + socle <- dockerfiler_dock_from_renv( lockfile = lockfile, distro = distro, FROM = FROM, diff --git a/R/boostrap_cli.R b/R/boostrap_cli.R index d26cb117..aff16776 100644 --- a/R/boostrap_cli.R +++ b/R/boostrap_cli.R @@ -10,7 +10,9 @@ check_cli_installed <- function(reason = "to have attractive command line interf cli_cat_bullet <- function(...) { check_cli_installed() - cli::cat_bullet(...) + do_if_unquiet({ + cli::cat_bullet(...) + )) } diff --git a/R/create_golem.R b/R/create_golem.R index ad013b04..4add58e5 100644 --- a/R/create_golem.R +++ b/R/create_golem.R @@ -240,7 +240,8 @@ create_golem <- function( if (isTRUE(open)) { if ( rlang::is_installed("rstudioapi") && - rstudioapi::isAvailable() && rstudioapi::hasFun("openProject") + rstudioapi::isAvailable() && + rstudioapi::hasFun("openProject") ) { rstudioapi::openProject(path = path) } else { diff --git a/R/sanity_check.R b/R/sanity_check.R index 6d2d5a34..3acc72fb 100644 --- a/R/sanity_check.R +++ b/R/sanity_check.R @@ -41,8 +41,13 @@ sanity_check <- function(pkg = get_golem_wd()) { if (length(source_markers) > 0) { if ( - rlang::is_installed("rstudioapi") && rstudioapi::isAvailable() && rstudioapi::hasFun("sourceMarkers")) { - rstudioapi::sourceMarkers("sanity_check", markers = source_markers) + rlang::is_installed("rstudioapi") && + rstudioapi::isAvailable() && + rstudioapi::hasFun("sourceMarkers")) { + rstudioapi::sourceMarkers( + "sanity_check", + markers = source_markers + ) } return(source_markers) } else { diff --git a/R/utils.R b/R/utils.R index 497a4551..ef475bc1 100644 --- a/R/utils.R +++ b/R/utils.R @@ -226,11 +226,9 @@ open_or_go_to <- function( open_file ) { if ( - rstudioapi::isAvailable() && - open_file && - rstudioapi::hasFun("navigateToFile") + open_file ) { - rstudioapi::navigateToFile(where) + rstudioapi_navigateToFile(where) } else { cat_red_bullet( sprintf( From 942c998745b54457ab88185a77764ef1bda9c1b5 Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 23 Dec 2022 10:39:47 +0100 Subject: [PATCH 41/55] fix: hotix typo --- R/boostrap_cli.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/boostrap_cli.R b/R/boostrap_cli.R index aff16776..8f9a9eda 100644 --- a/R/boostrap_cli.R +++ b/R/boostrap_cli.R @@ -12,7 +12,7 @@ cli_cat_bullet <- function(...) { check_cli_installed() do_if_unquiet({ cli::cat_bullet(...) - )) + }) } From bf03e50fa52054de84b6d30a4929088c7538f47d Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 23 Dec 2022 11:13:57 +0100 Subject: [PATCH 42/55] typo: hotfix typo message check_dev_deps_are_installed --- R/install_dev_deps.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/install_dev_deps.R b/R/install_dev_deps.R index 1a0926ac..d86dc2e8 100644 --- a/R/install_dev_deps.R +++ b/R/install_dev_deps.R @@ -96,7 +96,7 @@ check_dev_deps_are_installed <- function() { ) if (!all(are_installed)) { message( - "We noticed that some dev dependencies are not installed.", + "We noticed that some dev dependencies are not installed.\n", "You can install them with `install_dev_deps()`." ) } From 5eb61fb3b51fae9424eb0a65d7c142dd8fd48b9b Mon Sep 17 00:00:00 2001 From: vincent guyader Date: Fri, 20 Jan 2023 22:01:27 +0100 Subject: [PATCH 43/55] Update add_dockerfiles_renv.R (#976) fix : allow using `add_dockerfile_with_renv without` attachment and/or detect if package is missing --- R/add_dockerfiles_renv.R | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/R/add_dockerfiles_renv.R b/R/add_dockerfiles_renv.R index a784db2e..5a13be88 100644 --- a/R/add_dockerfiles_renv.R +++ b/R/add_dockerfiles_renv.R @@ -12,11 +12,21 @@ add_dockerfile_with_renv_ <- function( update_tar_gz = TRUE # build_golem_from_source = TRUE, ) { + + if (is.null(lockfile)) { + rlang::check_installed( + "attachment", + reason = "to build a Dockerfile with automatic renv.lock creation. Use the `lockfile` parameter to pass your own `renv.lock` file." + ) + + } + + + rlang::check_installed( - "renv", + "renv", reason = "to build a Dockerfile." ) - # Small hack to prevent warning from rlang::lang() in tests # This should be managed in {attempt} later on x <- suppressWarnings({ @@ -31,6 +41,7 @@ add_dockerfile_with_renv_ <- function( } if (is.null(lockfile)) { + lockfile <- attachment_create_renv_for_prod( path = source_folder, output = file.path(output_dir, "renv.lock.prod") From 3e11e48b3608a47713956d9c630c5a2d65b14237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rochette?= Date: Sat, 28 Jan 2023 18:43:11 +0100 Subject: [PATCH 44/55] fix: allow to build readme in 01_start tags: fix, doc Why? - I need to be able to commit right after running the complete "dev/01_dev.R" How? - To commit, I need the Readme.md file to be created, after I created the Readme.Rmd file. - devtools::build_readme() allows to install the package temporarily with its last version to be able to knit the Readme.Rmd in the last good conditions --- inst/shinyexample/dev/01_start.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inst/shinyexample/dev/01_start.R b/inst/shinyexample/dev/01_start.R index 24eee49e..7a963694 100644 --- a/inst/shinyexample/dev/01_start.R +++ b/inst/shinyexample/dev/01_start.R @@ -39,6 +39,7 @@ golem::install_dev_deps() ## See ?usethis for more information usethis::use_mit_license("Golem User") # You can set another license here usethis::use_readme_rmd(open = FALSE) +devtools::build_readme() # Note that `contact` is required since usethis version 2.1.5 # If your {usethis} version is older, you can remove that param usethis::use_code_of_conduct(contact = "Golem User") @@ -64,4 +65,4 @@ golem::use_utils_server(with_test = TRUE) # You're now set! ---- # go to dev/02_dev.R -rstudioapi::navigateToFile("dev/02_dev.R") \ No newline at end of file +rstudioapi::navigateToFile("dev/02_dev.R") From e1142e454a6f140e93c062304c0af8573be24740 Mon Sep 17 00:00:00 2001 From: vincent guyader Date: Sun, 29 Jan 2023 09:51:14 +0100 Subject: [PATCH 45/55] draft : Temp (#977) * Pass `require_suggets` to `attachment_create_renv_for_prod` * feat : force check_if_suggests_is_installed = FALSE in renv creation * feat : add test to check suggested package are not in renv.lock * fix : explictly use library(appname) before launching an app un Dockerfile issue : #978 * fix : update add_dockerfile_with_renv * fix : check_installed is more cleaver * fix : add {renv} to dev_deps (its already in {dockerfiler}'s deps, but it seems safer to do this. --------- Co-authored-by: Stephen Holsenbeck --- DESCRIPTION | 2 +- R/add_dockerfiles.R | 6 +-- R/add_dockerfiles_renv.R | 79 ++++++++++++++++++++++---------- R/bootstrap_attachment.R | 6 ++- R/install_dev_deps.R | 3 +- man/dockerfiles.Rd | 18 ++++++-- man/get_golem_options.Rd | 28 +++++------ tests/testthat/helper-config.R | 15 ++++++ tests/testthat/test-renv_stuff.R | 34 +++++++++----- 9 files changed, 131 insertions(+), 60 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9d73703a..ef1e936a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -66,4 +66,4 @@ Config/testthat/edition: 3 Encoding: UTF-8 Language: en-US Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.2 +RoxygenNote: 7.2.3 diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index 4901aef5..6565c7a1 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -165,7 +165,7 @@ add_dockerfile_ <- talk_once( dock$CMD( sprintf( - "R -e \"options('shiny.port'=%s,shiny.host='%s');%s::run_app()\"", + "R -e \"options('shiny.port'=%s,shiny.host='%s');library(%3$s);%3$s::run_app()\"", port, host, read.dcf(path)[1] @@ -263,7 +263,7 @@ add_dockerfile_shinyproxy_ <- talk_once( dock$EXPOSE(3838) dock$CMD(sprintf( - " [\"R\", \"-e\", \"options('shiny.port'=3838,shiny.host='0.0.0.0');%s::run_app()\"]", + " [\"R\", \"-e\", \"options('shiny.port'=3838,shiny.host='0.0.0.0');library(%1$s);%1$s::run_app()\"]", read.dcf(path)[1] )) dock$write(output) @@ -357,7 +357,7 @@ add_dockerfile_heroku_ <- talk_once( dock$CMD( sprintf( - "R -e \"options('shiny.port'=$PORT,shiny.host='0.0.0.0');%s::run_app()\"", + "R -e \"options('shiny.port'=$PORT,shiny.host='0.0.0.0');library(%1$s);%1$s::run_app()\"", read.dcf(path)[1] ) ) diff --git a/R/add_dockerfiles_renv.R b/R/add_dockerfiles_renv.R index 5a13be88..9c38a977 100644 --- a/R/add_dockerfiles_renv.R +++ b/R/add_dockerfiles_renv.R @@ -9,24 +9,21 @@ add_dockerfile_with_renv_ <- function( repos = c(CRAN = "https://cran.rstudio.com/"), expand = FALSE, extra_sysreqs = NULL, - update_tar_gz = TRUE + update_tar_gz = TRUE, + document = FALSE, + ... # build_golem_from_source = TRUE, ) { - + if (is.null(lockfile)) { rlang::check_installed( - "attachment", + c("renv","attachment"), reason = "to build a Dockerfile with automatic renv.lock creation. Use the `lockfile` parameter to pass your own `renv.lock` file." ) - + } - - - - rlang::check_installed( - "renv", - reason = "to build a Dockerfile." - ) + + # Small hack to prevent warning from rlang::lang() in tests # This should be managed in {attempt} later on x <- suppressWarnings({ @@ -41,10 +38,28 @@ add_dockerfile_with_renv_ <- function( } if (is.null(lockfile)) { - + + + if ( isTRUE(document) ){ + + cli_cat_line("You set `document = TRUE` and you did not pass your own renv.lock file,") + cli_cat_line("as a consequence {golem} will use `attachment::att_amend_desc()` to update your ") + cli_cat_line("DESCRIPTION file before creating the renv.lock file") + cli_cat_line("") + cli_cat_line("you can set `document = FALSE` to use your actual DESCRIPTION file,") + cli_cat_line("or pass you own renv.lock to use, using the `lockfile` parameter") + cli_cat_line("") + cli_cat_line("In any case be sure to have no Error or Warning at `devtools::check()`") + } + + + + lockfile <- attachment_create_renv_for_prod( path = source_folder, - output = file.path(output_dir, "renv.lock.prod") + check_if_suggests_is_installed = FALSE, document = document, + output = file.path(output_dir, "renv.lock.prod"), + ... ) } @@ -132,8 +147,10 @@ add_dockerfile_with_renv_ <- function( #' @param output_dir folder to export everything deployment related. #' @param distro One of "focal", "bionic", "xenial", "centos7", or "centos8". #' See available distributions at https://hub.docker.com/r/rstudio/r-base/. +#' @param document boolean. If TRUE (by default), DESCRIPTION file is updated using [attachment::att_amend_desc()] before creating the renv.lock file #' @param dockerfile_cmd What is the CMD to add to the Dockerfile. If NULL, the default, -#' the CMD will be `R -e "options('shiny.port'={port},shiny.host='{host}');{appname}::run_app()\` +#' the CMD will be `R -e "options('shiny.port'={port},shiny.host='{host}');library({appname});{appname}::run_app()\` +#' @param ... Other arguments to pass to [renv::snapshot()] #' @inheritParams add_dockerfile #' @rdname dockerfiles #' @export @@ -150,9 +167,11 @@ add_dockerfile_with_renv <- function( repos = c(CRAN = "https://cran.rstudio.com/"), expand = FALSE, open = TRUE, + document = TRUE, extra_sysreqs = NULL, update_tar_gz = TRUE, - dockerfile_cmd = NULL + dockerfile_cmd = NULL, + ... ) { base_dock <- add_dockerfile_with_renv_( source_folder = source_folder, @@ -165,14 +184,16 @@ add_dockerfile_with_renv <- function( repos = repos, expand = expand, extra_sysreqs = extra_sysreqs, - update_tar_gz = update_tar_gz + update_tar_gz = update_tar_gz, + document = document, + ... ) if (!is.null(port)) { base_dock$EXPOSE(port) } if (is.null(dockerfile_cmd)) { dockerfile_cmd <- sprintf( - "R -e \"options('shiny.port'=%s,shiny.host='%s');%s::run_app()\"", + "R -e \"options('shiny.port'=%s,shiny.host='%s');library(%3$s);%3$s::run_app()\"", port, host, golem::get_golem_name() @@ -205,7 +226,7 @@ docker run -p %s:%s %s ) } -#' @inheritParams add_dockerfile +#' @inheritParams add_dockerfile_with_renv #' @rdname dockerfiles #' @export #' @export @@ -221,7 +242,9 @@ add_dockerfile_with_renv_shinyproxy <- function( expand = FALSE, extra_sysreqs = NULL, open = TRUE, - update_tar_gz = TRUE + document = TRUE, + update_tar_gz = TRUE, + ... ) { add_dockerfile_with_renv( source_folder = source_folder, @@ -238,14 +261,16 @@ add_dockerfile_with_renv_shinyproxy <- function( extra_sysreqs = extra_sysreqs, update_tar_gz = update_tar_gz, open = open, + document = document, dockerfile_cmd = sprintf( - "R -e \"options('shiny.port'=3838,shiny.host='0.0.0.0');%s::run_app()\"", + "R -e \"options('shiny.port'=3838,shiny.host='0.0.0.0');library(%1$s);%1$s::run_app()\"", golem::get_golem_name() - ) + ), + ... ) } -#' @inheritParams add_dockerfile +#' @inheritParams add_dockerfile_with_renv #' @rdname dockerfiles #' @export #' @export @@ -261,7 +286,9 @@ add_dockerfile_with_renv_heroku <- function( expand = FALSE, extra_sysreqs = NULL, open = TRUE, - update_tar_gz = TRUE + document = TRUE, + update_tar_gz = TRUE, + ... ) { add_dockerfile_with_renv( source_folder = source_folder, @@ -278,10 +305,12 @@ add_dockerfile_with_renv_heroku <- function( extra_sysreqs = extra_sysreqs, update_tar_gz = update_tar_gz, open = FALSE, + document = document, dockerfile_cmd = sprintf( - "R -e \"options('shiny.port'=$PORT,shiny.host='0.0.0.0');%s::run_app()\"", + "R -e \"options('shiny.port'=$PORT,shiny.host='0.0.0.0');library(%1$s);%1$s::run_app()\"", golem::get_golem_name() - ) + ), + ... ) apps_h <- gsub( diff --git a/R/bootstrap_attachment.R b/R/bootstrap_attachment.R index 887b6939..0f0e831d 100644 --- a/R/bootstrap_attachment.R +++ b/R/bootstrap_attachment.R @@ -3,7 +3,7 @@ check_attachment_installed <- function() { rlang::check_installed( "attachment", - version = "0.2.5", + version = "0.3.1", reason = "to build a Dockerfile." ) } @@ -12,12 +12,16 @@ attachment_create_renv_for_prod <- function( path = ".", output = "renv.lock.prod", dev_pkg = "remotes", + check_if_suggests_is_installed = FALSE, + document = FALSE, ... ) { attachment::create_renv_for_prod( path = path, output = output, dev_pkg = dev_pkg, + document = document, + check_if_suggests_is_installed = check_if_suggests_is_installed, ... ) } diff --git a/R/install_dev_deps.R b/R/install_dev_deps.R index d86dc2e8..cffab779 100644 --- a/R/install_dev_deps.R +++ b/R/install_dev_deps.R @@ -82,6 +82,7 @@ dev_deps <- unique( "pkgload", "processx", "roxygen2", + "renv", "rsconnect", "rstudioapi", "testthat", @@ -97,7 +98,7 @@ check_dev_deps_are_installed <- function() { if (!all(are_installed)) { message( "We noticed that some dev dependencies are not installed.\n", - "You can install them with `install_dev_deps()`." + "You can install them with `golem::install_dev_deps()`." ) } } diff --git a/man/dockerfiles.Rd b/man/dockerfiles.Rd index 6a54e1a0..04536333 100644 --- a/man/dockerfiles.Rd +++ b/man/dockerfiles.Rd @@ -69,9 +69,11 @@ add_dockerfile_with_renv( repos = c(CRAN = "https://cran.rstudio.com/"), expand = FALSE, open = TRUE, + document = TRUE, extra_sysreqs = NULL, update_tar_gz = TRUE, - dockerfile_cmd = NULL + dockerfile_cmd = NULL, + ... ) add_dockerfile_with_renv_shinyproxy( @@ -86,7 +88,9 @@ add_dockerfile_with_renv_shinyproxy( expand = FALSE, extra_sysreqs = NULL, open = TRUE, - update_tar_gz = TRUE + document = TRUE, + update_tar_gz = TRUE, + ... ) add_dockerfile_with_renv_heroku( @@ -101,7 +105,9 @@ add_dockerfile_with_renv_heroku( expand = FALSE, extra_sysreqs = NULL, open = TRUE, - update_tar_gz = TRUE + document = TRUE, + update_tar_gz = TRUE, + ... ) } \arguments{ @@ -154,8 +160,12 @@ default is current folder '.'} \item{distro}{One of "focal", "bionic", "xenial", "centos7", or "centos8". See available distributions at https://hub.docker.com/r/rstudio/r-base/.} +\item{document}{boolean. If TRUE (by default), DESCRIPTION file is updated using \code{\link[attachment:att_amend_desc]{attachment::att_amend_desc()}} before creating the renv.lock file} + \item{dockerfile_cmd}{What is the CMD to add to the Dockerfile. If NULL, the default, -the CMD will be \verb{R -e "options('shiny.port'=\{port\},shiny.host='\{host\}');\{appname\}::run_app()\\}} +the CMD will be \verb{R -e "options('shiny.port'=\{port\},shiny.host='\{host\}');library(\{appname\});\{appname\}::run_app()\\}} + +\item{...}{Other arguments to pass to \code{\link[renv:snapshot]{renv::snapshot()}}} } \value{ The \code{{dockerfiler}} object, invisibly. diff --git a/man/get_golem_options.Rd b/man/get_golem_options.Rd index 0eadfabc..6f8a2a6c 100644 --- a/man/get_golem_options.Rd +++ b/man/get_golem_options.Rd @@ -23,10 +23,12 @@ parameters passed to \code{run_app()}. if (interactive()) { # 1. Pass parameters directly to `run_app` - run_app( title="My Golem App", - content = "something" ) + run_app( + title = "My Golem App", + content = "something" + ) - # 2. Get the values + # 2. Get the values # 2.1 from the UI side h1(get_golem_options("title")) @@ -36,17 +38,17 @@ if (interactive()) { output$param <- renderPrint({ paste("param content = ", get_golem_options("content")) }) - + output$param_full <- renderPrint({ - get_golem_options() # list of all golem options as a list. + get_golem_options() # list of all golem options as a list. }) - + # 3. If needed, to set default value, edit `run_app` like this : run_app <- function( - title = "this", - content = "that", - ... + title = "this", + content = "that", + ... ) { with_golem_options( app = shinyApp( @@ -54,14 +56,12 @@ if (interactive()) { server = app_server ), golem_opts = list( - title = title, - content = content, - ... + title = title, + content = content, + ... ) ) } - - } } diff --git a/tests/testthat/helper-config.R b/tests/testthat/helper-config.R index 5105773b..81554197 100644 --- a/tests/testthat/helper-config.R +++ b/tests/testthat/helper-config.R @@ -93,3 +93,18 @@ withr::with_dir(pkg, { ) usethis::use_mit_license("Golem") }) + + +create_deploy_folder <- function(){ +file.path( + tempdir(), + make.names( + paste0( + "deploy", + round( + runif(1, min = 0, max = 99999) + ) + ) + ) + ) +} diff --git a/tests/testthat/test-renv_stuff.R b/tests/testthat/test-renv_stuff.R index f63449e4..07853af1 100644 --- a/tests/testthat/test-renv_stuff.R +++ b/tests/testthat/test-renv_stuff.R @@ -8,17 +8,7 @@ test_that("add_dockerfiles_renv and add_dockerfile_with_renv_shinyproxy all outp add_dockerfile_with_renv_shinyproxy, add_dockerfile_with_renv_heroku )) { - deploy_folder <- file.path( - tempdir(), - make.names( - paste0( - "deploy", - round( - runif(1, min = 0, max = 99999) - ) - ) - ) - ) + deploy_folder <- create_deploy_folder() fun(output_dir = deploy_folder, open = FALSE) @@ -32,3 +22,25 @@ test_that("add_dockerfiles_renv and add_dockerfile_with_renv_shinyproxy all outp } }) }) +test_that("suggested package ore not in renv prod", { + skip_if_not_installed("renv") + skip_if_not_installed("dockerfiler", "0.2.0") + skip_if_not_installed("attachment", "0.3.1") + with_dir(pkg, { + desc_file <- file.path("DESCRIPTION") + desc_lines <- readLines(desc_file) + # desc_lines <- c(desc_lines,"Suggests: \n idontexist") + desc_lines[desc_lines == "Suggests: "] <- "Suggests: \n idontexist," + writeLines(desc_lines,desc_file) + deploy_folder <- create_deploy_folder() + + add_dockerfile_with_renv(output_dir = deploy_folder, open = FALSE) + + base <- paste(readLines(file.path(deploy_folder,"renv.lock.prod")),collapse = " ") + expect_false(grepl(pattern = "idontexist",x = base)) + expect_true(grepl(pattern = "shiny",x = base)) + + unlink(deploy_folder, force = TRUE, recursive = TRUE) + } + ) +}) From f576d0f7a6e23331ce971f579d917939c872c090 Mon Sep 17 00:00:00 2001 From: vincent guyader Date: Sun, 29 Jan 2023 10:20:26 +0100 Subject: [PATCH 46/55] fix : URLs are now OK # 980 (#981) --- vignettes/a_start.Rmd | 4 ++-- vignettes/b_dev.Rmd | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vignettes/a_start.Rmd b/vignettes/a_start.Rmd index 0dd31ef2..6e17673c 100644 --- a/vignettes/a_start.Rmd +++ b/vignettes/a_start.Rmd @@ -124,7 +124,7 @@ golem::fill_desc( ) ``` -About [the DESCRIPTION file](https://r-pkgs.org/Metadata.html#sec-description). +About [the DESCRIPTION file](https://r-pkgs.org/description.html). ### Add `{golem}` options @@ -157,7 +157,7 @@ Create a template for tests: golem::use_recommended_tests() ``` -About [tests in a package](https://r-pkgs.org/tests.html). +About [tests in a package](https://r-pkgs.org/testing-basics.html). ### Use Recommended Packages diff --git a/vignettes/b_dev.Rmd b/vignettes/b_dev.Rmd index c0b41100..367484af 100644 --- a/vignettes/b_dev.Rmd +++ b/vignettes/b_dev.Rmd @@ -45,7 +45,7 @@ Note that the `{attachment}` package should be installed on your machine. attachment::att_amend_desc() ``` -About [package dependencies](https://r-pkgs.org/Metadata.html#sec-namespace). +About [package dependencies](https://r-pkgs.org/dependencies-mindset-background.html). ### Add modules From da7cbe73b57516466b2e37b298e502091cdf5a87 Mon Sep 17 00:00:00 2001 From: IlyaZar Date: Wed, 22 Feb 2023 15:19:41 +0100 Subject: [PATCH 47/55] Fix #993 --- inst/shinyexample/REMOVEME.Rbuildignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inst/shinyexample/REMOVEME.Rbuildignore b/inst/shinyexample/REMOVEME.Rbuildignore index f3162bb5..9b9a10f3 100644 --- a/inst/shinyexample/REMOVEME.Rbuildignore +++ b/inst/shinyexample/REMOVEME.Rbuildignore @@ -3,4 +3,5 @@ ^data-raw$ dev_history.R ^dev$ -$run_dev.* \ No newline at end of file +$run_dev.* +^.here$ From 9c09c01bcd70315f404006728d5f5b59515e260b Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 6 Mar 2023 15:23:44 +0100 Subject: [PATCH 48/55] test: new test and deploy script --- inst/mantests/build.R | 693 ++++++++++++++++++++---------------------- 1 file changed, 332 insertions(+), 361 deletions(-) diff --git a/inst/mantests/build.R b/inst/mantests/build.R index 3e761bf1..668de34f 100644 --- a/inst/mantests/build.R +++ b/inst/mantests/build.R @@ -1,5 +1,40 @@ +# To test locally, run this in a docker container: +# docker run -d --rm -v $(pwd):/home/golem rocker/shiny:latest tail -f /dev/null +# Attach VSCode to the container +# Then run this script in the terminal + +# This script is launched internally by ThinkR every day by our GitLab CI +temp_app <- commandArgs(TRUE)[1] +if (is.na(temp_app)) { + temp_app <- "/golemmetrics" +} +cli::cat_bullet(temp_app) +if (dir.exists(temp_app)) { + unlink(temp_app, TRUE, TRUE) +} +install.packages(c("pak")) + +if (!rlang::is_installed("cli")) { + pak::pak("cli") +} + +if (!rlang::is_installed("testthat")) { + pak::pak("testthat") +} + +if (!rlang::is_installed("desc")) { + pak::pak("desc") +} + +if (!rlang::is_installed("devtools")) { + pak::pak("devtools") +} + +library(desc) +library(testthat) cat("\n") + # rstudioapi::jobRunScript(here::here("inst/mantests/build.R"), workingDir = here::here()) cat_ok <- function() cli::cat_bullet("Passed", bullet = "tick", bullet_col = "green") @@ -16,416 +51,352 @@ fakename <- sprintf( gsub("[ :-]", "", Sys.time()) ) -# Just so that I can use this script locally too, -# I set a temporary lib -cli::cat_rule("Set up for lib") +cli::cat_rule("Installing the dev version of golem") +pak::pak("thinkr-open/golem@dev") -temp_app <- file.path(tempdir(), "golemmetrics") - -if (Sys.getenv("CI", "local") == "local") { - # If I'm on the CI, we don't change the lib - temp_lib <- .libPaths() -} else { - temp_lib <- file.path(tempdir(), "temp_lib") - .libPaths(c(temp_lib, .libPaths())) -} +cli::cat_rule("Install crystalmountains") +pak::pak( + "thinkr-open/crystalmountains" +) -cli::cat_bullet(temp_app) -# This will be our golem app +cli::cat_rule("Creating a golem based app") +# Going to the temp dir and create a new golem +cli::cat_rule("Creating a golem based app") +library(golem) -if (dir.exists(temp_app)) { - unlink(temp_app, TRUE, TRUE) -} +zz <- file("all.Rout", open = "wt") +sink(zz) +sink(zz, type = "message") -dir.create(temp_lib, recursive = TRUE) +# This is our temp app -install.packages( - c("remotes", "desc", "testthat", "cli", "fs", "cranlogs", "pak"), - lib = temp_lib, - repo = "https://cran.rstudio.com/" +create_golem( + temp_app, + open = FALSE, + project_hook = crystalmountains::golem_hook ) +sink(type = "message") +sink() -cli::cat_rule("Install golem") - -library(remotes, lib.loc = temp_lib) -library(desc, lib.loc = temp_lib) -library(testthat, lib.loc = temp_lib) -library(cli, lib.loc = temp_lib) -library(fs, lib.loc = temp_lib) - -# We'll need to install golem from the current branch because -# otherwise the dependency tree breaks -# install_github( -# "ThinkR-open/golem", -# ref = Sys.getenv("GITHUB_BASE_REF", "dev"), -# force = TRUE, -# lib.loc = temp_lib -# ) - -# Installing the current version of golem -install_local( - lib.loc = temp_lib +expect_true( + dir.exists(temp_app) ) -golem::install_dev_deps( - force_install = TRUE, - lib = temp_lib +expect_true( + any(grepl( + "golem::install_dev_deps()", + readLines("all.Rout") + )) ) +unlink("all.Rout", TRUE, TRUE) -withr::with_tempdir({ - cli::cat_rule("Install crystalmountains") - - remotes::install_github( - "thinkr-open/crystalmountains", - lib.loc = temp_lib, - update = "never" - ) - - here::set_here(getwd()) - # Going to the temp dir and create a new golem - cli::cat_rule("Creating a golem based app") - library(golem) - - create_golem( - temp_app, - open = FALSE, - project_hook = crystalmountains::golem_hook - ) +golem::install_dev_deps(force = TRUE) +for (pak in golem:::dev_deps) { expect_true( - dir.exists(temp_app) + rlang::is_installed(pak) ) +} - old <- setwd(temp_app) +old <- setwd(temp_app) - here::set_here(temp_app) +usethis::use_build_ignore(".here") - usethis::use_build_ignore(".here") +cat( + readLines("DESCRIPTION"), + sep = "\n" +) - if (Sys.getenv("GITHUB_BASE_REF") == "") { - usethis::use_dev_package( - "golem", - remote = "github::ThinkR-open/golem@dev" - ) - } else { - usethis::use_dev_package( - "golem", - remote = sprintf( - "github::ThinkR-open/golem@dev", - Sys.getenv("GITHUB_BASE_REF") - ) - ) - } +usethis::use_build_ignore(".here") +usethis::use_dev_package("golem") +cat( + readLines("DESCRIPTION"), + sep = "\n" +) - cat( - readLines("DESCRIPTION"), - sep = "\n" - ) +cat_ok() - here::set_here(temp_app) +cli::cat_rule("Checking the hook has set the MIT licence") +expect_true( + file.exists("LICENSE") +) +expect_true( + desc_get("License") == "MIT + file LICENSE" +) +cat_ok() - usethis::use_build_ignore(".here") +cli::cat_rule("Checking the DESCRIPTION is correct") +expect_true( + desc_get("Package") == "golemmetrics" +) +expect_true( + desc_get("Title") == "An Amazing Shiny App" +) +expect_true( + all(desc_get_deps()$package %in% c("config", "golem", "shiny")) +) +cat_ok() + +cli::cat_rule("Checking all files are here") + +expected_files <- c( + "DESCRIPTION", + "NAMESPACE", + "R", + "R/app_config.R", + "R/app_server.R", + "R/app_ui.R", + "R/run_app.R", + "dev", + "dev/01_start.R", + "dev/02_dev.R", + "dev/03_deploy.R", + "dev/run_dev.R", + "inst", + "inst/app", + "inst/app/www", + "inst/app/www/favicon.ico", + "inst/golem-config.yml", + "man", + "man/run_app.Rd" +) +actual_files <- fs::dir_ls(recurse = TRUE) - usethis::use_dev_package("golem") +for (i in expected_files) { + expect_true(i %in% actual_files) +} +cat_ok() + +# Going through 01_start.R ---- +# +cli::cat_rule("Going through 01_start.R") +cli::cat_line() + +golem::fill_desc( + pkg = temp_app, + pkg_name = "golemmetrics", # The Name of the package containing the App + pkg_title = "A App with Metrics about 'Golem'", # The Title of the package containing the App + pkg_description = "Read metrics about {golem}.", # The Description of the package containing the App + author_first_name = "Colin", # Your First Name + author_last_name = "Fay", # Your Last Name + author_email = "colin@thinkr.fr", # Your Email + repo_url = NULL, # The URL of the GitHub Repo (optional) + pkg_version = "0.0.0.9000" # The Version of the package containing the App +) - cat( - readLines("DESCRIPTION"), - sep = "\n" - ) +cli::cat_rule("checking package name") +expect_equal( + desc_get_field("Package"), + "golemmetrics" +) +cat_ok() +cli::cat_rule("checking pkg_title name") +expect_equal( + desc_get_field("Title"), + "A App with Metrics about 'Golem'" +) +cat_ok() +cli::cat_rule("checking package name") +expect_equal( + desc_get_field("Description"), + "Read metrics about {golem}." +) +cat_ok() +cli::cat_rule("checking package name") +expect_equal( + as.character(desc_get_author()), + "Colin Fay [cre, aut]" +) +cat_ok() +cli::cat_rule("checking package version") +expect_equal( + as.character(desc_get_version()), + "0.0.0.9000" +) +cat_ok() - cat_ok() +cli::cat_rule("set_golem_options") +golem::set_golem_options() +expect_equal( + golem::get_golem_wd(), + golem::pkg_path() +) +expect_equal( + golem::get_golem_name(), + "golemmetrics" +) +expect_equal( + golem::get_golem_version(), + "0.0.0.9000" +) +expect_false( + golem::app_prod() +) - cli::cat_rule("Checking the hook has set the MIT licence") - expect_true( - file.exists("LICENSE") - ) - expect_true( - desc_get("License") == "MIT + file LICENSE" - ) - cat_ok() +cat_ok() - cli::cat_rule("Checking the DESCRIPTION is correct") - expect_true( - desc_get("Package") == "golemmetrics" - ) - expect_true( - desc_get("Title") == "An Amazing Shiny App" - ) - expect_true( - all(desc_get_deps()$package %in% c("config", "golem", "shiny")) - ) - cat_ok() - - cli::cat_rule("Checking all files are here") - - expected_files <- c( - "DESCRIPTION", - "NAMESPACE", - "R", - "R/app_config.R", - "R/app_server.R", - "R/app_ui.R", - "R/run_app.R", - "dev", - "dev/01_start.R", - "dev/02_dev.R", - "dev/03_deploy.R", - "dev/run_dev.R", - "inst", - "inst/app", - "inst/app/www", - "inst/app/www/favicon.ico", - "inst/golem-config.yml", - "man", - "man/run_app.Rd" - ) - actual_files <- fs::dir_ls(recurse = TRUE) - - for (i in expected_files) { - expect_true(i %in% actual_files) - } - cat_ok() - - # Going through 01_start.R ---- - # - cli::cat_rule("Going through 01_start.R") - cli::cat_line() - - golem::fill_desc( - pkg = temp_app, - pkg_name = "golemmetrics", # The Name of the package containing the App - pkg_title = "A App with Metrics about 'Golem'", # The Title of the package containing the App - pkg_description = "Read metrics about {golem}.", # The Description of the package containing the App - author_first_name = "Colin", # Your First Name - author_last_name = "Fay", # Your Last Name - author_email = "colin@thinkr.fr", # Your Email - repo_url = NULL, # The URL of the GitHub Repo (optional) - pkg_version = "0.0.0.9000" # The Version of the package containing the App - ) +cli::cat_rule("Create Common Files") - cli::cat_rule("checking package name") - expect_equal( - desc_get_field("Package"), - "golemmetrics" - ) - cat_ok() - cli::cat_rule("checking pkg_title name") - expect_equal( - desc_get_field("Title"), - "A App with Metrics about 'Golem'" - ) - cat_ok() - cli::cat_rule("checking package name") - expect_equal( - desc_get_field("Description"), - "Read metrics about {golem}." - ) - cat_ok() - cli::cat_rule("checking package name") - expect_equal( - as.character(desc_get_author()), - "Colin Fay [cre, aut]" - ) - cat_ok() - cli::cat_rule("checking package version") - expect_equal( - as.character(desc_get_version()), - "0.0.0.9000" - ) - cat_ok() - - cli::cat_rule("set_golem_options") - - golem::set_golem_options() - expect_equal( - golem::get_golem_wd(), - golem::pkg_path() - ) - expect_equal( - golem::get_golem_name(), - "golemmetrics" - ) - expect_equal( - golem::get_golem_version(), - "0.0.0.9000" - ) - expect_false( - golem::app_prod() - ) +# usethis::use_mit_license( "Golem User" ) - cat_ok() +expect_equal( + desc_get_field("License"), + "MIT + file LICENSE" +) +expect_true( + file.exists("LICENSE") +) +usethis::use_readme_rmd(open = FALSE) +expect_true( + file.exists("README.Rmd") +) - cli::cat_rule("Create Common Files") +usethis::use_code_of_conduct("Golem user") +expect_true( + file.exists("CODE_OF_CONDUCT.md") +) - # usethis::use_mit_license( "Golem User" ) +usethis::use_news_md(open = FALSE) +expect_true( + file.exists("NEWS.md") +) - expect_equal( - desc_get_field("License"), - "MIT + file LICENSE" - ) - expect_true( - file.exists("LICENSE") - ) - usethis::use_readme_rmd(open = FALSE) - expect_true( - file.exists("README.Rmd") - ) +cat_ok() - usethis::use_code_of_conduct("Golem user") - expect_true( - file.exists("CODE_OF_CONDUCT.md") - ) +cli::cat_rule("use_recommended") - usethis::use_news_md(open = FALSE) - expect_true( - file.exists("NEWS.md") - ) +golem::use_recommended_tests(spellcheck = FALSE) +expect_true( + dir.exists("tests") +) - cat_ok() +# golem::use_recommended_deps() - cli::cat_rule("use_recommended") +golem::use_utils_ui(with_test = TRUE) +expect_true( + file.exists("R/golem_utils_ui.R") +) +expect_true( + file.exists("tests/testthat/test-golem_utils_ui.R") +) - golem::use_recommended_tests(spellcheck = FALSE) - expect_true( - dir.exists("tests") - ) +golem::use_utils_server() +expect_true( + file.exists("R/golem_utils_server.R") +) - # golem::use_recommended_deps() +cat_ok() - golem::use_utils_ui(with_test = TRUE) - expect_true( - file.exists("R/golem_utils_ui.R") - ) - expect_true( - file.exists("tests/testthat/test-golem_utils_ui.R") - ) +# Going through 02_dev ---- +cli::cat_rule("Going through 02_dev.R") - golem::use_utils_server() - expect_true( - file.exists("R/golem_utils_server.R") - ) +cli::cat_rule("Testing usepackage") +if (!requireNamespace("cranlogs")) { + pak::pak("cranlogs") +} +usethis::use_package("cranlogs") +expect_true( + "cranlogs" %in% desc_get_deps()$package +) +cat_ok() + +cli::cat_rule("Testing modules") +golem::add_module( + name = "main", + open = FALSE, + module_template = crystalmountains::module_template, + fct = "golem_logs", + js = "golem_stars", + utils = "pretty_num" +) - cat_ok() +expect_true( + file.exists("R/mod_main.R") +) - # Going through 02_dev ---- - cli::cat_rule("Going through 02_dev.R") +expect_true( + file.exists("R/mod_main_fct_golem_logs.R") +) +write( + readLines( + system.file( + "golemlogs", + package = "crystalmountains" + ) + ), + "R/mod_main_fct_golem_logs.R", + append = TRUE +) +expect_true( + file.exists("R/mod_main_utils_pretty_num.R") +) +write( + readLines( + system.file( + "prettynum", + package = "crystalmountains" + ) + ), + "R/mod_main_utils_pretty_num.R", + append = TRUE +) +expect_true( + file.exists("inst/app/www/golem_stars.js") +) +unlink("inst/app/www/golem_stars.js", TRUE, TRUE) - cli::cat_rule("Testing usepackage") - if (!requireNamespace("cranlogs")) { - install.packages("cranlogs") - } - usethis::use_package("cranlogs") - expect_true( - "cranlogs" %in% desc_get_deps()$package - ) - cat_ok() - - cli::cat_rule("Testing modules") - golem::add_module( - name = "main", - open = FALSE, - module_template = crystalmountains::module_template, - fct = "golem_logs", - js = "golem_stars", - utils = "pretty_num" - ) +golem::document_and_reload() - expect_true( - file.exists("R/mod_main.R") - ) +cat_ok() - expect_true( - file.exists("R/mod_main_fct_golem_logs.R") - ) - write( - readLines( - system.file( - "golemlogs", - package = "crystalmountains" - ) - ), - "R/mod_main_fct_golem_logs.R", - append = TRUE - ) - expect_true( - file.exists("R/mod_main_utils_pretty_num.R") - ) - write( - readLines( - system.file( - "prettynum", - package = "crystalmountains" - ) - ), - "R/mod_main_utils_pretty_num.R", - append = TRUE - ) - expect_true( - file.exists("inst/app/www/golem_stars.js") - ) - unlink("inst/app/www/golem_stars.js", TRUE, TRUE) +golem::add_fct("helpers", open = FALSE) +expect_true( + file.exists("R/fct_helpers.R") +) +unlink("R/fct_helpers.R", TRUE, TRUE) +golem::add_utils("helpers", open = FALSE) +expect_true( + file.exists("R/utils_helpers.R") +) +unlink("R/utils_helpers.R", TRUE, TRUE) + +golem::add_js_file("script", template = crystalmountains::js_file, open = FALSE) +golem::add_js_handler("handlers", template = crystalmountains::js_handler, open = FALSE) +golem::add_css_file("custom", template = crystalmountains::css_file, open = FALSE) + +cli::cat_rule("Testing and installing package") +golem::document_and_reload() +devtools::test() +cat_ok() + +cli::cat_rule("Testing 03_dev") +devtools::check() +remotes::install_local(force = TRUE, upgrade = FALSE) +targz <- devtools::build() +remotes::install_local(targz, force = TRUE, upgrade = FALSE) + +cat_ok() + +golem::add_rstudioconnect_file() + +golem::add_dockerfile_with_renv( + repos = "https://packagemanager.rstudio.com/all/__linux__/focal/latest", + from = "rocker/shiny-verse:4.0.4", + extra_sysreqs = c("libxml2-dev"), + open = FALSE, + output_dir = "/golemmetrics/deploy", + document = FALSE +) - golem::document_and_reload() +# Restore old wd - cat_ok() +# unlink(temp_app, TRUE, TRUE) +# unlink(temp_golem, TRUE, TRUE) +# unlink(temp_lib, TRUE, TRUE) - golem::add_fct("helpers", open = FALSE) - expect_true( - file.exists("R/fct_helpers.R") - ) - unlink("R/fct_helpers.R", TRUE, TRUE) - golem::add_utils("helpers", open = FALSE) - expect_true( - file.exists("R/utils_helpers.R") - ) - unlink("R/utils_helpers.R", TRUE, TRUE) - - golem::add_js_file("script", template = crystalmountains::js_file) - golem::add_js_handler("handlers", template = crystalmountains::js_handler) - golem::add_css_file("custom", template = crystalmountains::css_file) - - cli::cat_rule("Testing and installing package") - golem::document_and_reload() - devtools::test() - cat_ok() - - cli::cat_rule("Testing 03_dev") - devtools::check() - remotes::install_local(force = TRUE) - targz <- devtools::build() - remotes::install_local(targz) - - cli::cat_rule("Testing 03_dev") - - cat_ok() - - if (Sys.info()["sysname"] == "Linux") { - golem::add_rstudioconnect_file() - golem::add_dockerfile( - repos = "https://packagemanager.rstudio.com/all/__linux__/focal/latest", - from = "rocker/shiny-verse:4.0.4", - extra_sysreqs = c("libxml2-dev"), - open = FALSE - ) - usethis::use_git() - dir.create(".git/hooks", recursive = TRUE) - file.create(".git/hooks/pre-commit") - install.packages("rsconnect") - rsconnect::writeManifest() - install.packages("knitr") - knitr::knit("README.Rmd") - } - - # Restore old wd - - # unlink(temp_app, TRUE, TRUE) - # unlink(temp_golem, TRUE, TRUE) - # unlink(temp_lib, TRUE, TRUE) - - cli::cat_rule("Completed") -}) +cli::cat_rule("Completed") From bbcc392234d7f485524f1e31085a4b2ba4d7d3ee Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 6 Mar 2023 15:44:26 +0100 Subject: [PATCH 49/55] ci: forcing the repos --- inst/mantests/build.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inst/mantests/build.R b/inst/mantests/build.R index 668de34f..22dfb032 100644 --- a/inst/mantests/build.R +++ b/inst/mantests/build.R @@ -13,6 +13,8 @@ if (dir.exists(temp_app)) { unlink(temp_app, TRUE, TRUE) } +options("repos" = "https://packagemanager.posit.co/cran/__linux__/jammy/latest") + install.packages(c("pak")) if (!rlang::is_installed("cli")) { From a926b4c44619f687a0a00adf7f860b964860528b Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 7 Mar 2023 09:04:54 +0100 Subject: [PATCH 50/55] ci: updated GA --- .github/workflows/R-CMD-check.yaml | 49 +++++++++++ .github/workflows/check-standard.yaml | 112 -------------------------- 2 files changed, 49 insertions(+), 112 deletions(-) create mode 100644 .github/workflows/R-CMD-check.yaml delete mode 100644 .github/workflows/check-standard.yaml diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 00000000..a3ac6182 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,49 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true diff --git a/.github/workflows/check-standard.yaml b/.github/workflows/check-standard.yaml deleted file mode 100644 index 0b0fa965..00000000 --- a/.github/workflows/check-standard.yaml +++ /dev/null @@ -1,112 +0,0 @@ -# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. -# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions -on: - push: - branches: - - main - - master - - dev - pull_request: - branches: - - main - - master - - dev - -name: R-CMD-check - -jobs: - R-CMD-check: - runs-on: ${{ matrix.config.os }} - - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) - - strategy: - fail-fast: false - matrix: - config: - - { os: windows-latest, r: "release" } - - { os: macOS-latest, r: "release" } - - { - os: ubuntu-20.04, - r: "release", - rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", - } - - env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v1 - with: - r-version: ${{ matrix.config.r }} - - - uses: r-lib/actions/setup-pandoc@v1 - - - name: Query dependencies - run: | - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v2 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install system dependencies - if: runner.os == 'Linux' - run: | - while read -r cmd - do - eval sudo $cmd - done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') - - - name: Install dependencies - run: | - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} - - - name: Check - env: - _R_CHECK_CRAN_INCOMING_REMOTE_: false - run: | - options(crayon.enabled = TRUE) - rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} - - - name: Manual Test - if: runner.os != 'Windows' - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - run: | - source("inst/mantests/build.R") - shell: Rscript {0} - - # - name: Pushes to another repository - # uses: cpina/github-action-push-to-another-repository@main - # if: runner.os == 'Linux' - # env: - # API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} - # with: - # source-directory: "inst/golemmetrics" - # destination-github-username: "colinfay" - # destination-repository-username: "thinkr-open" - # destination-repository-name: "golemmetrics" - # user-email: contact@colinfay.me - # target-branch: main - - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main - with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check From a9051e67ca129d558055d14c7c6ae49d8917df40 Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 7 Mar 2023 09:11:00 +0100 Subject: [PATCH 51/55] ci: use_dev_package in build.R --- inst/mantests/build.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inst/mantests/build.R b/inst/mantests/build.R index 22dfb032..98069b56 100644 --- a/inst/mantests/build.R +++ b/inst/mantests/build.R @@ -373,6 +373,12 @@ golem::add_css_file("custom", template = crystalmountains::css_file, open = FALS cli::cat_rule("Testing and installing package") golem::document_and_reload() + +usethis::use_dev_package( + "golem", + remotes = "https://github.com/ThinkR-open/golem" +) + devtools::test() cat_ok() From 585cc03a782b9b14c043fc7b39e58fce5380bdea Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 10 Mar 2023 10:27:45 +0100 Subject: [PATCH 52/55] doc: only one return tag --- R/is_running.R | 1 - R/make_dev.R | 1 - man/is_running.Rd | 2 -- man/prod.Rd | 2 -- 4 files changed, 6 deletions(-) diff --git a/R/is_running.R b/R/is_running.R index 4c0c50c2..69d0e760 100644 --- a/R/is_running.R +++ b/R/is_running.R @@ -7,7 +7,6 @@ #' FALSE otherwise. #' @export #' -#' @return A boolean. #' @examples #' is_running() is_running <- function() { diff --git a/R/make_dev.R b/R/make_dev.R index ce5ff1ea..24489ad4 100644 --- a/R/make_dev.R +++ b/R/make_dev.R @@ -26,7 +26,6 @@ make_dev <- function(fun) { #' @export #' #' @rdname prod -#' @return A boolean. app_prod <- function() { getOption("golem.app.prod") %||% FALSE } diff --git a/man/is_running.Rd b/man/is_running.Rd index b7605526..adb6cee7 100644 --- a/man/is_running.Rd +++ b/man/is_running.Rd @@ -9,8 +9,6 @@ is_running() \value{ TRUE if the running app is a \code{{golem}} based app, FALSE otherwise. - -A boolean. } \description{ Note that this will return \code{TRUE} only if the application diff --git a/man/prod.Rd b/man/prod.Rd index bdabc03a..9255c15b 100644 --- a/man/prod.Rd +++ b/man/prod.Rd @@ -11,8 +11,6 @@ app_dev() } \value{ \code{TRUE} or \code{FALSE} depending on the status of \code{getOption( "golem.app.prod")} - -A boolean. } \description{ Is the app in dev mode or prod mode? From 1b4018a70e0bef7541f9f19b6bd6a9cc1f4b06bc Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 10 Mar 2023 11:31:48 +0100 Subject: [PATCH 53/55] doc: doc cleaning before CRAN release --- .Rbuildignore | 1 + R/add_dockerfiles.R | 225 ++++++++++++++++---------------- R/install_dev_deps.R | 7 +- R/pkg_tools.R | 7 +- README.Rmd | 28 +++- README.md | 77 ++++++++++- cran-comments.md | 27 ++-- man/install_dev_deps.Rd | 4 + man/pkg_tools.Rd | 3 + vignettes/f_extending_golem.Rmd | 84 ++++++------ 10 files changed, 282 insertions(+), 181 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index c460e46a..e7cb3cb1 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -22,3 +22,4 @@ ^Meta$ ^\.github$ ^revdep$ +README.html \ No newline at end of file diff --git a/R/add_dockerfiles.R b/R/add_dockerfiles.R index 6565c7a1..5d1c54d5 100644 --- a/R/add_dockerfiles.R +++ b/R/add_dockerfiles.R @@ -83,26 +83,25 @@ talk_once <- function(.f, msg = "") { #' } #' @return The `{dockerfiler}` object, invisibly. add_dockerfile <- function( - path = "DESCRIPTION", - output = "Dockerfile", - pkg = get_golem_wd(), - from = paste0( - "rocker/verse:", - R.Version()$major, - ".", - R.Version()$minor - ), - as = NULL, - port = 80, - host = "0.0.0.0", - sysreqs = TRUE, - repos = c(CRAN = "https://cran.rstudio.com/"), - expand = FALSE, - open = TRUE, - update_tar_gz = TRUE, - build_golem_from_source = TRUE, - extra_sysreqs = NULL -) { + path = "DESCRIPTION", + output = "Dockerfile", + pkg = get_golem_wd(), + from = paste0( + "rocker/verse:", + R.Version()$major, + ".", + R.Version()$minor + ), + as = NULL, + port = 80, + host = "0.0.0.0", + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + open = TRUE, + update_tar_gz = TRUE, + build_golem_from_source = TRUE, + extra_sysreqs = NULL) { add_dockerfile_( path = path, output = output, @@ -123,26 +122,25 @@ add_dockerfile <- function( add_dockerfile_ <- talk_once( function( - path = "DESCRIPTION", - output = "Dockerfile", - pkg = get_golem_wd(), - from = paste0( - "rocker/verse:", - R.Version()$major, - ".", - R.Version()$minor - ), - as = NULL, - port = 80, - host = "0.0.0.0", - sysreqs = TRUE, - repos = c(CRAN = "https://cran.rstudio.com/"), - expand = FALSE, - open = TRUE, - update_tar_gz = TRUE, - build_golem_from_source = TRUE, - extra_sysreqs = NULL - ) { + path = "DESCRIPTION", + output = "Dockerfile", + pkg = get_golem_wd(), + from = paste0( + "rocker/verse:", + R.Version()$major, + ".", + R.Version()$minor + ), + as = NULL, + port = 80, + host = "0.0.0.0", + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + open = TRUE, + update_tar_gz = TRUE, + build_golem_from_source = TRUE, + extra_sysreqs = NULL) { where <- fs_path(pkg, output) usethis_use_build_ignore( @@ -191,24 +189,23 @@ add_dockerfile_ <- talk_once( #' @export #' @rdname dockerfiles add_dockerfile_shinyproxy <- function( - path = "DESCRIPTION", - output = "Dockerfile", - pkg = get_golem_wd(), - from = paste0( - "rocker/verse:", - R.Version()$major, - ".", - R.Version()$minor - ), - as = NULL, - sysreqs = TRUE, - repos = c(CRAN = "https://cran.rstudio.com/"), - expand = FALSE, - open = TRUE, - update_tar_gz = TRUE, - build_golem_from_source = TRUE, - extra_sysreqs = NULL -) { + path = "DESCRIPTION", + output = "Dockerfile", + pkg = get_golem_wd(), + from = paste0( + "rocker/verse:", + R.Version()$major, + ".", + R.Version()$minor + ), + as = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + open = TRUE, + update_tar_gz = TRUE, + build_golem_from_source = TRUE, + extra_sysreqs = NULL) { add_dockerfile_shinyproxy_( path = path, output = output, @@ -227,24 +224,23 @@ add_dockerfile_shinyproxy <- function( add_dockerfile_shinyproxy_ <- talk_once( function( - path = "DESCRIPTION", - output = "Dockerfile", - pkg = get_golem_wd(), - from = paste0( - "rocker/verse:", - R.Version()$major, - ".", - R.Version()$minor - ), - as = NULL, - sysreqs = TRUE, - repos = c(CRAN = "https://cran.rstudio.com/"), - expand = FALSE, - open = TRUE, - update_tar_gz = TRUE, - build_golem_from_source = TRUE, - extra_sysreqs = NULL - ) { + path = "DESCRIPTION", + output = "Dockerfile", + pkg = get_golem_wd(), + from = paste0( + "rocker/verse:", + R.Version()$major, + ".", + R.Version()$minor + ), + as = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + open = TRUE, + update_tar_gz = TRUE, + build_golem_from_source = TRUE, + extra_sysreqs = NULL) { where <- fs_path(pkg, output) usethis_use_build_ignore(output) @@ -285,24 +281,23 @@ add_dockerfile_shinyproxy_ <- talk_once( #' @export #' @rdname dockerfiles add_dockerfile_heroku <- function( - path = "DESCRIPTION", - output = "Dockerfile", - pkg = get_golem_wd(), - from = paste0( - "rocker/verse:", - R.Version()$major, - ".", - R.Version()$minor - ), - as = NULL, - sysreqs = TRUE, - repos = c(CRAN = "https://cran.rstudio.com/"), - expand = FALSE, - open = TRUE, - update_tar_gz = TRUE, - build_golem_from_source = TRUE, - extra_sysreqs = NULL -) { + path = "DESCRIPTION", + output = "Dockerfile", + pkg = get_golem_wd(), + from = paste0( + "rocker/verse:", + R.Version()$major, + ".", + R.Version()$minor + ), + as = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + open = TRUE, + update_tar_gz = TRUE, + build_golem_from_source = TRUE, + extra_sysreqs = NULL) { add_dockerfile_heroku_( path = path, output = output, @@ -321,24 +316,23 @@ add_dockerfile_heroku <- function( add_dockerfile_heroku_ <- talk_once( function( - path = "DESCRIPTION", - output = "Dockerfile", - pkg = get_golem_wd(), - from = paste0( - "rocker/verse:", - R.Version()$major, - ".", - R.Version()$minor - ), - as = NULL, - sysreqs = TRUE, - repos = c(CRAN = "https://cran.rstudio.com/"), - expand = FALSE, - open = TRUE, - update_tar_gz = TRUE, - build_golem_from_source = TRUE, - extra_sysreqs = NULL - ) { + path = "DESCRIPTION", + output = "Dockerfile", + pkg = get_golem_wd(), + from = paste0( + "rocker/verse:", + R.Version()$major, + ".", + R.Version()$minor + ), + as = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + open = TRUE, + update_tar_gz = TRUE, + build_golem_from_source = TRUE, + extra_sysreqs = NULL) { where <- fs_path(pkg, output) usethis_use_build_ignore(output) @@ -409,10 +403,9 @@ golem::add_dockerfile_heroku() is not recommended anymore.\nPlease use golem::ad ) alert_build <- function( - path, - output, - build_golem_from_source -) { + path, + output, + build_golem_from_source) { cat_created(output, "Dockerfile") if (!build_golem_from_source) { cat_red_bullet( diff --git a/R/install_dev_deps.R b/R/install_dev_deps.R index cffab779..25595856 100644 --- a/R/install_dev_deps.R +++ b/R/install_dev_deps.R @@ -28,10 +28,11 @@ #' if (interactive()) { #' install_dev_deps() #' } +#' +#' @return Used for side-effects install_dev_deps <- function( - force_install = FALSE, - ... -) { + force_install = FALSE, + ...) { if (!force_install) { if (!interactive()) { # In non interactive mode with force_install turned to FALSE, diff --git a/R/pkg_tools.R b/R/pkg_tools.R index ab3aa4b4..adf26591 100644 --- a/R/pkg_tools.R +++ b/R/pkg_tools.R @@ -1,8 +1,7 @@ # Getting the DESCRIPTION file in a data.frame daf_desc <- function( - path = ".", - entry -) { + path = ".", + entry) { as.character( unlist( unname( @@ -27,6 +26,8 @@ daf_desc <- function( #' #' @export #' @rdname pkg_tools +#' +#' @return The value of the entry in the DESCRIPTION file pkg_name <- function(path = ".") { daf_desc(path, "Package") } diff --git a/README.Rmd b/README.Rmd index 28555092..6fcea973 100644 --- a/README.Rmd +++ b/README.Rmd @@ -7,7 +7,7 @@ output: github_document ```{r setup, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, - eval = FALSE, + eval = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%", @@ -27,8 +27,27 @@ knitr::opts_chunk$set( ## About -You're reading the doc about version : ``r as.data.frame(read.dcf("DESCRIPTION"))$Version `` +You're reading the doc about version : `r pkgload::pkg_version()` +This README has been compiled on the + +```{r} +Sys.time() +``` + +Here are the test & coverage results : + +```{r} +devtools::check(quiet = TRUE) +``` + +```{r echo = FALSE} +unloadNamespace("golem") +``` + +```{r} +covr::package_coverage() +``` ## Tool series @@ -37,13 +56,14 @@ This package is part of a series of tools for Shiny, which includes: - `{golem}` - - `{shinipsum}` - - `{fakir}` - -- `{shinysnippets}` - +- `{gemstones}` - ## Resources ### The Book : - + - [paper version of the book “Engineering Production-Grade Shiny Apps”](https://www.routledge.com/Engineering-Production-Grade-Shiny-Apps/Fay-Rochette-Guyader-Girard/p/book/9780367466022) ### Blog posts : @@ -69,7 +89,7 @@ This package is part of a series of tools for Shiny, which includes: - [Hands-on demonstration of {golem}](https://www.youtube.com/watch?v=3-p9XLvoJV0) - useR! 2019 : [A Framework for Building Robust & Production Ready Shiny Apps](https://youtu.be/tCAan6smrjs) - `r emo::flag("France")` [Introduction to {golem}](https://youtu.be/6qI4NzxlAFU) -- rstudio::conf(2020) : [Production-grade Shiny Apps with golem](https://www.rstudio.com/resources/rstudioconf-2020/production-grade-shiny-apps-with-golem/) +- rstudio::conf(2020) : [Production-grade Shiny Apps with golem](https://posit.co/resources/videos/production-grade-shiny-apps-with-golem/) - `r emo::flag("France")` Rencontres R 2021 : [ Conception d'applications Shiny avec {golem}](https://www.youtube.com/watch?v=0f5Me1PFGDs) - `r emo::flag("France")` [ Déploiement d'une application {shiny} dans docker avec {renv} et {golem}](https://www.youtube.com/watch?v=diCG4t76k78) diff --git a/README.md b/README.md index e70d5dda..a5feac9d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,77 @@ shiny applications. ## About -You’re reading the doc about version : `0.4.0` +You’re reading the doc about version : 0.4.0 + +This README has been compiled on the + +``` r +Sys.time() +#> [1] "2023-03-10 09:53:27 CET" +``` + +Here are the test & coverage results : + +``` r +devtools::check(quiet = TRUE) +#> ℹ Loading golem +#> ── R CMD check results ──────────────────────────────────────── golem 0.4.0 ──── +#> Duration: 1m 23.6s +#> +#> 0 errors ✔ | 0 warnings ✔ | 0 notes ✔ +``` + +``` r +covr::package_coverage() +#> golem Coverage: 69.16% +#> R/addins.R: 0.00% +#> R/bootstrap_rstudio_api.R: 0.00% +#> R/enable_roxygenize.R: 0.00% +#> R/get_sysreqs.R: 0.00% +#> R/gobals.R: 0.00% +#> R/run_dev.R: 0.00% +#> R/sanity_check.R: 0.00% +#> R/use_files.R: 0.00% +#> R/with_opt.R: 22.58% +#> R/config.R: 28.21% +#> R/test_helpers.R: 30.26% +#> R/js.R: 43.75% +#> R/reload.R: 45.36% +#> R/use_recommended.R: 54.55% +#> R/bootstrap_desc.R: 55.56% +#> R/install_dev_deps.R: 57.14% +#> R/utils.R: 58.30% +#> R/bootstrap_attachment.R: 61.54% +#> R/add_dockerfiles.R: 74.19% +#> R/bootstrap_usethis.R: 76.56% +#> R/boostrap_fs.R: 77.78% +#> R/modules_fn.R: 80.00% +#> R/use_utils.R: 83.33% +#> R/use_favicon.R: 85.56% +#> R/desc.R: 86.25% +#> R/add_resource_path.R: 88.89% +#> R/create_golem.R: 89.47% +#> R/make_dev.R: 90.00% +#> R/add_r_files.R: 91.67% +#> R/add_files.R: 92.31% +#> R/add_rstudio_files.R: 93.10% +#> R/golem-yaml-get.R: 93.18% +#> R/bootstrap_dockerfiler.R: 93.33% +#> R/add_dockerfiles_renv.R: 93.75% +#> R/boostrap_cli.R: 100.00% +#> R/boostrap_crayon.R: 100.00% +#> R/bootstrap_pkgload.R: 100.00% +#> R/bootstrap_roxygen2.R: 100.00% +#> R/browser_button.R: 100.00% +#> R/bundle_resources.R: 100.00% +#> R/disable_autoload.R: 100.00% +#> R/golem-yaml-set.R: 100.00% +#> R/golem-yaml-utils.R: 100.00% +#> R/is_running.R: 100.00% +#> R/pkg_tools.R: 100.00% +#> R/set_golem_options.R: 100.00% +#> R/templates.R: 100.00% +``` ## Tool series @@ -28,13 +98,14 @@ This package is part of a series of tools for Shiny, which includes: - `{golem}` - - `{shinipsum}` - - `{fakir}` - -- `{shinysnippets}` - +- `{gemstones}` - ## Resources ### The Book : - + - [paper version of the book “Engineering Production-Grade Shiny Apps”](https://www.routledge.com/Engineering-Production-Grade-Shiny-Apps/Fay-Rochette-Guyader-Girard/p/book/9780367466022) @@ -72,7 +143,7 @@ scratch*](https://towardsdatascience.com/production-grade-r-shiny-with-golem-pro Apps](https://youtu.be/tCAan6smrjs) - 🇫🇷 [Introduction to {golem}](https://youtu.be/6qI4NzxlAFU) - rstudio::conf(2020) : [Production-grade Shiny Apps with - golem](https://www.rstudio.com/resources/rstudioconf-2020/production-grade-shiny-apps-with-golem/) + golem](https://posit.co/resources/videos/production-grade-shiny-apps-with-golem/) - 🇫🇷 Rencontres R 2021 : [Conception d’applications Shiny avec {golem}](https://www.youtube.com/watch?v=0f5Me1PFGDs) - 🇫🇷 [Déploiement d’une application {shiny} dans docker avec {renv} et diff --git a/cran-comments.md b/cran-comments.md index 35b82c24..30c1d7ba 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,15 +1,24 @@ -## R CMD check results +# R CMD check results -0 errors | 0 warnings | 0 note +0 errors ✔ | 0 warnings ✔ | 0 notes ✔ -* This is a submission that fixes the issue from the CRAN check page. +# Revdeps +## Failed to check (7) -=> The new version of testthat fails when unloaded during the tests. This new version of golem removes the test that unloads testthat. +|package |version |error |warning |note | +|:---------------|:-------|:-----|:-------|:----| +|discoveR |3.1.2 |1 | | | +|loadeR |1.1.3 |1 | | | +|multiSight |? | | | | +|OlympicRshiny |1.0.0 |1 | | | +|shinyTempSignal |0.0.3 |1 | | | +|spatialLIBD |1.10.1 |1 | |2 | +|tripr |1.4.0 |1 | | | -## revdepcheck results +## New problems (1) -We checked 31 reverse dependencies (17 from CRAN + 14 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package. - - * We saw 0 new problems - * We failed to check 0 packages +|package |version |error |warning |note | +|:--------------------|:-------|:-----|:-------|:----| +|MainExistingDatasets|1.0.1 | |__+1__ |1 | +> This has been addressed by a PR on the git repo: https://github.com/baptisteCD/MainExistingDatasets/pull/1 \ No newline at end of file diff --git a/man/install_dev_deps.Rd b/man/install_dev_deps.Rd index 34835239..22f7fce8 100644 --- a/man/install_dev_deps.Rd +++ b/man/install_dev_deps.Rd @@ -13,6 +13,9 @@ to install them.} \item{...}{further arguments passed to the install function.} } +\value{ +Used for side-effects +} \description{ This function will run rlang::check_installed() on: \itemize{ @@ -37,4 +40,5 @@ This function will run rlang::check_installed() on: if (interactive()) { install_dev_deps() } + } diff --git a/man/pkg_tools.Rd b/man/pkg_tools.Rd index a2c40e54..d9a5869a 100644 --- a/man/pkg_tools.Rd +++ b/man/pkg_tools.Rd @@ -15,6 +15,9 @@ pkg_path() \arguments{ \item{path}{Path to use to read the DESCRIPTION} } +\value{ +The value of the entry in the DESCRIPTION file +} \description{ These are functions to help you navigate inside your project while developing diff --git a/vignettes/f_extending_golem.Rmd b/vignettes/f_extending_golem.Rmd index 24cd694c..4fcae1c6 100644 --- a/vignettes/f_extending_golem.Rmd +++ b/vignettes/f_extending_golem.Rmd @@ -15,18 +15,18 @@ knitr::opts_chunk$set( ) ``` -This Vignette discusses how you can extend `{golem}`. +This Vignette discusses how you can extend `{golem}`. ## Project Hooks ### What it is -The `create_golem()` function comes with a `project_hook` parameter, a function run just after the `{golem}` project creation. -It can be used to modify the project structure automatically just after its creation. +The `create_golem()` function comes with a `project_hook` parameter, a function run just after the `{golem}` project creation. +It can be used to modify the project structure automatically just after its creation. This allows you to define custom behavior when creating `{golem}` based app, that can be used for: -+ Adding a different front-end template in `R/app_ui.R` ++ Adding a different front-end template in `R/app_ui.R` + Changing configuration options in `inst/golem-config.yml` @@ -36,24 +36,24 @@ This allows you to define custom behavior when creating `{golem}` based app, tha + etc. -### How it works +### How it works -The function is called __after__ the default project has been created, and is executed __in the directory of the created package__. +The function is called __after__ the default project has been created, and is executed __in the directory of the created package__. Here is a rough step by step of what happens when a project is created with `{golem}`: 1. The package name is generated -1. The directory that will receive the package is created +1. The directory that will receive the package is created 1. Default `{golem}` template is copied and pasted 1. R moves to the directory of the newly created project, and runs the `project_hook` function 1. R moves back to the previous directory, and removes comments if needed -1. Project is open +1. Project is open ### Defining your own `project_hook` -The best way to extend `{golem}` project hook functionality is by defining this `project_hook` function in an external package. -This will allow this function to be used inside the `{golem}` creation RStudio project creation widget: +The best way to extend `{golem}` project hook functionality is by defining this `project_hook` function in an external package. +This will allow this function to be used inside the `{golem}` creation RStudio project creation widget: -![](rstudioprojecthook.png) +![](rstudioprojecthook.png) > Note that inside this widget, the function should be explicitely namespaced (pkg::fun) @@ -76,7 +76,7 @@ no_dev <- function(path, package_name, ...) { create_golem("ici", project_hook = no_dev) ``` -This one will create a CSS: +This one will create a CSS: ```{r} new_css <- function(path, package_name, ...) { @@ -103,12 +103,12 @@ create_golem("ici", project_hook = new_css) ### What it is Module templates are a way to define your own content for creating the module script in `R/`. -It allows to extend `{golem}` module template functionality by creating your own content inside the module file. +It allows to extend `{golem}` module template functionality by creating your own content inside the module file. -### How it works +### How it works -The function is called after the file(s) creation. -Here is a step by step of what happens when the `add_module` function is called: +The function is called after the file(s) creation. +Here is a step by step of what happens when the `add_module` function is called: 1. Name is created, and so is the `R/` directory if needed. 1. The fct_ and utils_ files are created if necessary @@ -121,9 +121,9 @@ Here is a step by step of what happens when the `add_module` function is called: ### Defining your own `module_template` -You can then define your own function inside your `{golem}` based application, but chances are you will be defining them into your own package. +You can then define your own function inside your `{golem}` based application, but chances are you will be defining them into your own package. -Module template functions will receive, by default, the following parameters from `add_modules()`. +Module template functions will receive, by default, the following parameters from `add_modules()`. + `name`: the name of the module + `path`: the path to the file in R/ @@ -157,10 +157,10 @@ golem::add_module(name = "custom", module_template = my_other_tmpl) JavaScript, CSS and Sass template allow to use your own functions to add code when creating JavaScript files, JavaScript handlers and CSS or Sass files. These templates work inside `add_js_file()`, `add_js_handler()`, `add_css_file()` and `add_sass_file()`. -### How it works +### How it works -The function is called after the file creation. -Here is a step by step of what happens when these functions are called: +The function is called after the file creation. +Here is a step by step of what happens when these functions are called: 1. Name is created 1. The path is generated @@ -172,11 +172,11 @@ Here is a step by step of what happens when these functions are called: ### Defining your own `template` -You can then define your own function inside your `{golem}` based application, but chances are you will be defining them into your own package. +You can then define your own function inside your `{golem}` based application, but chances are you will be defining them into your own package. -File template functions will receive, by default, the following parameters from the `add_*()` function. +File template functions will receive, by default, the following parameters from the `add_*()` function. -+ `path`: the path to the file ++ `path`: the path to the file + `...` further arguments These parameters might not be used inside your own function, but __they need to be set in the function skeleton__, for compatibility reasons. @@ -202,7 +202,7 @@ golem::add_css_file(name = "custom", template = my_tmpl) ### What it is -From time to time, you need your application to be unavailbel: database update, API changes, etc. +From time to time, you need your application to be unavailble: database update, API changes, etc. In order to keep your app running but make it unavailable, you can use a __maintenance mode__. When this maintenance mode is turned on, your application will be paused and a specific page will be displayed to your users. @@ -210,9 +210,9 @@ When this maintenance mode is turned on, your application will be paused and a s ### How to set the maintenance mode -The maintenance mode will be turned on whenever the R process detects that the `GOLEM_MAINTENANCE_ACTIVE` environment variable is set to TRUE. +The maintenance mode will be turned on whenever the R process detects that the `GOLEM_MAINTENANCE_ACTIVE` environment variable is set to TRUE. -To visualise the maintenance page locally, you can run the following: +To visualize the maintenance page locally, you can run the following: ```{r eval = FALSE} withr::with_envvar( @@ -233,9 +233,9 @@ golem::run_dev() -If you're deploying on Posit Connect, you can set this variable in the setup panel. +If you're deploying on Posit Connect, you can set this variable in the setup panel. -If in command line, you can also do +If in command line, you can also do ``` export GOLEM_MAINTENANCE_ACTIVE=TRUE && Rscript -e "mygolem::run_app()" @@ -244,18 +244,17 @@ export GOLEM_MAINTENANCE_ACTIVE=TRUE && Rscript -e "mygolem::run_app()" ### The maintenance page -`{golem}` comes with a default maintenance page, but you can override it and use your own custom page. +`{golem}` comes with a default maintenance page, but you can override it and use your own custom page. In order to use your own page, you need to pass either an `html_document` or a `tagList` to the `with_golem_options` function in `run_app.R`: ```{r} run_app <- function( - onStart = NULL, - options = list(), - enableBookmarking = NULL, - uiPattern = "/", - ... -) { + onStart = NULL, + options = list(), + enableBookmarking = NULL, + uiPattern = "/", + ...) { with_golem_options( app = shinyApp( ui = app_ui, @@ -276,16 +275,15 @@ run_app <- function( } ``` -or: +or: ```{r} run_app <- function( - onStart = NULL, - options = list(), - enableBookmarking = NULL, - uiPattern = "/", - ... -) { + onStart = NULL, + options = list(), + enableBookmarking = NULL, + uiPattern = "/", + ...) { with_golem_options( app = shinyApp( ui = app_ui, From 08f050f65074102057df39c1228810e2ad95b3e6 Mon Sep 17 00:00:00 2001 From: vincent guyader Date: Wed, 7 Dec 2022 13:19:03 +0100 Subject: [PATCH 54/55] Fix 944 and correct CI * fix #944 force lowercase for package name in Dockerfile * check_is_installed is back again instead of fs_file_copy for dockerfile creation * set version to 0.3.5.9001 --- NEWS.md | 372 +++++++++++++++++++-------------------- R/add_dockerfiles_renv.R | 160 ++++++++--------- R/utils.R | 42 +++++ 3 files changed, 303 insertions(+), 271 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7e9765e3..053a765b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,42 +1,38 @@ > Notes: the # between parenthesis referes to the related issue on GitHub, and the @ refers to an external contributor solving this issue. -# 0.3.5.9000+ (dev version) - -## Soft deprecated - -## Hard deprecated +# 0.4.0 ## New functions -+ Add `add_partial_html_template()` to create a partial html template, with "just" a div and a `{{ }}` (@nathansquan #858). - +- Add `add_partial_html_template()` to create a partial html template, with only a div and a `{{ }}` (@nathansquan #858). ## New features / user visible changes -+ The following hard dependencies have been moved to soft dependencies, as you'll only need them while developing: `{pkgload}`, `{roxygen2}`, `{fs}`, `{usethis}`, `{cli}`, `{crayon}` -+ Soft dependency check is now done via `rlang::check_installed()` (#835) -+ `golem::run_dev()` has been refactored to match the behavior of other functions, notably it now uses `golem::get_golem_wd()` to find the current working dir. -+ `{golem}` now depends on `{rlang}` version >= 1.0.0 -+ Functions that print to the console are now quiet if `options("golem.quiet" = TRUE)`, #793 -+ Small documentation update in dockerfile related functions (#939) -+ `fill_desc()` now allows to set the version (#877) -+ Setting the Environment variable `GOLEM_MAINTENANCE_ACTIVE` to `TRUE` active the maintenance mode of your app -+ `golem::run_dev()` now save all open documents before sourcing the `dev/run_dev.R` file -+ When creating an app, you'll get a message if the dev deps are not all installed (#915) -+ 03_deploy now contains an example of sending the app to PositConnect or Shinyapps.io (#923) +- Dev hard dependencies have been moved to soft dependencies. You can see the list with `golem:::dev_deps`. They can be installed via `golem::install_dev_deps()`. +- Soft dependency check is now done via `rlang::check_installed()` (#835) +- `golem::run_dev()` has been refactored to match the behavior of other functions, notably it now uses `golem::get_golem_wd()` to find the current working dir. +- `{golem}` now depends on `{rlang}` version >= 1.0.0 +- Functions that print to the console are now quiet if `options("golem.quiet" = TRUE)`, #793 +- Small documentation update in dockerfile related functions (#939) +- `fill_desc()` now allows to set the version (#877) +- Setting the Environment variable `GOLEM_MAINTENANCE_ACTIVE` to `TRUE` active the maintenance mode of your app +- `golem::run_dev()` now save all open documents before sourcing the `dev/run_dev.R` file +- When creating an app, you'll get a message if the dev deps are not all installed (#915) +- 03_deploy now contains an example of sending the app to PositConnect or Shinyapps.io (#923) ## Bug fix -+ The message after htmlTemplate creation now suggests to add in the UI, not only in app_ui.R (#861) -+ The Deprecation message for `use_recommended_deps` no longer suggest to user `use_recommended_deps` (#900) -+ The setting of the config file has been unified so that we are sure to keep the !expr in `golem_set_wd()`, and the codebase has been simplified for this (#709). -+ The functions adding files can no longer take a `name` argument that has length() > 1. This used to cause some bugs (#781) -+ The typo in `install.packages()` in 02_dev.R has been corrected (@asiripanich) -+ `add_dockerfile_with_renv()` now works well with uppercase in package name -+ improve `get_golem_options()` documentation -## Internal changes +- The message after htmlTemplate creation now suggests to add in the UI, not only in app_ui.R (#861) +- The Deprecation message for `use_recommended_deps` no longer suggest to user `use_recommended_deps` (#900) +- The setting of the config file has been unified so that we are sure to keep the !expr in `golem_set_wd()`, and the codebase has been simplified for this (#709). +- The functions adding files can no longer take a `name` argument that has length() > 1. This used to cause some bugs (#781) +- The typo in `install.packages()` in 02_dev.R has been corrected (@asiripanich) +- `add_dockerfile_with_renv()` now works well with uppercase in package name +- improve `get_golem_options()` documentation +## Internal changes +add_dockerfile_with_renv now works well with uppercase in package name # golem 0.3.5 @@ -50,88 +46,87 @@ Update in the tests for CRAN (skip not installed + examples). ## New functions -+ `add_dockerfile_with_renv()`, `add_dockerfile_with_renv_heroku()` and `add_dockerfile_with_renv_shinyproxy()` build Dockerfiles that rely on `{renv}` +- `add_dockerfile_with_renv()`, `add_dockerfile_with_renv_heroku()` and `add_dockerfile_with_renv_shinyproxy()` build Dockerfiles that rely on `{renv}` ### Soft deprecated -+ `add_dockerfile`, `add_dockerfile_shinyproxy()` and `add_dockerfile_heroku()` now recommend to switch to their `_with_renv_` counterpart - +- `add_dockerfile`, `add_dockerfile_shinyproxy()` and `add_dockerfile_heroku()` now recommend to switch to their `_with_renv_` counterpart # golem 0.3.2 (CRAN VERSION) ### Soft deprecated -+ `use_recommended_deps()` is now soft deprecated (#786) +- `use_recommended_deps()` is now soft deprecated (#786) ### Hard deprecated -+ The `html` parameter in `expect_html_equal()` is no longer in use (#55). +- The `html` parameter in `expect_html_equal()` is no longer in use (#55). ## New functions -+ `add_sass_file()` creates a .sass file in inst/app/www (#768) +- `add_sass_file()` creates a .sass file in inst/app/www (#768) -+ `use_module_test()` creates a test skeleton for a module (#725) +- `use_module_test()` creates a test skeleton for a module (#725) ## New features -+ The `02_dev.R` file now suggests using `attachment::att_amend_desc()` (#787) +- The `02_dev.R` file now suggests using `attachment::att_amend_desc()` (#787) -+ `use_code_of_conduct()` in dev script now has the contact param (#812) +- `use_code_of_conduct()` in dev script now has the contact param (#812) -+ All `with_test` params are now TRUE in the dev script (#801) +- All `with_test` params are now TRUE in the dev script (#801) -+ `test-golem-recommended` now has two new tests for `app_sys` and `get_golem_config` (#751) +- `test-golem-recommended` now has two new tests for `app_sys` and `get_golem_config` (#751) -+ `use_utils_ui()` `use_utils_server()` & now come with a `with_test` parameter that adds a test file for theses functions (#625 & #801) +- `use_utils_ui()` `use_utils_server()` & now come with a `with_test` parameter that adds a test file for theses functions (#625 & #801) -+ `{golem}` now checks if a module exists before adding a module related file (#779) +- `{golem}` now checks if a module exists before adding a module related file (#779) -+ Every `{rstudioapi}` calls is now conditionned by the availabily of this function (#776) +- Every `{rstudioapi}` calls is now conditionned by the availabily of this function (#776) -+ `use_external_*` functions no longer suggest to "Go to" (#713, @novica) +- `use_external_*` functions no longer suggest to "Go to" (#713, @novica) -+ `create_golem()` now comes with `with_git` parameter that can be used to initialize git repository while creating a project template +- `create_golem()` now comes with `with_git` parameter that can be used to initialize git repository while creating a project template -+ `use_recommended_tests()` now comes with `testServer` (#720). +- `use_recommended_tests()` now comes with `testServer` (#720). -+ `expect_html_equal()` now uses `testthat::expect_snapshot()` (#55). +- `expect_html_equal()` now uses `testthat::expect_snapshot()` (#55). -+ `add_modules()`, `add_fct()` and `add_utils()` now come with a `with_test` parameter that can be turned on to add a test file to the module (#719 & #141) +- `add_modules()`, `add_fct()` and `add_utils()` now come with a `with_test` parameter that can be turned on to add a test file to the module (#719 & #141) -+ /!\ All docker related functions have been moved to `{dockerfiler}`. This is more or less a breaking change, cause you'll need to install `{dockerfiler}` > 0.1.4 in order to build the Dockerfile __but__ `{golem}` will ask you to install `{dockerfiler}` > 0.1.4 if it can't find it, (#412) +- /!\ All docker related functions have been moved to `{dockerfiler}`. This is more or less a breaking change, cause you'll need to install `{dockerfiler}` > 0.1.4 in order to build the Dockerfile **but** `{golem}` will ask you to install `{dockerfiler}` > 0.1.4 if it can't find it, (#412) -+ Modules ID no longer contain an `_ui_` element, (#651, @MargotBr) +- Modules ID no longer contain an `_ui_` element, (#651, @MargotBr) -+ run_dev now has `options(shiny.port = httpuv::randomPort())` to prevent the browser from caching the CSS & JS files (#675) +- run_dev now has `options(shiny.port = httpuv::randomPort())` to prevent the browser from caching the CSS & JS files (#675) -+ You can now specify the path to R in `expect_running()`. +- You can now specify the path to R in `expect_running()`. ## Bug fix -+ Fixed a bug in the printing of the htmlTemplate code (#827) +- Fixed a bug in the printing of the htmlTemplate code (#827) -+ We now require the correct `{usethis}` version (822) +- We now require the correct `{usethis}` version (822) -+ `golem::amend_config()` now keeps the `!expr` (#709, @teofiln) +- `golem::amend_config()` now keeps the `!expr` (#709, @teofiln) -+ recommended tests now use `expect_type()` instead of `expect_is`, which was deprecated from `{testthat}` (#671) +- recommended tests now use `expect_type()` instead of `expect_is`, which was deprecated from `{testthat}` (#671) -+ Fixed check warning when using `golem::use_utils_server()` (#678), +- Fixed check warning when using `golem::use_utils_server()` (#678), -+ Fixed issue with expect_running & path to R (#700, @waiteb5) +- Fixed issue with expect_running & path to R (#700, @waiteb5) -+ `expect_running()` now find R.exe on windows. +- `expect_running()` now find R.exe on windows. -+ `use_recommended_tests()` no longer add `{processx}` to the `DESCRIPTION` (#710) +- `use_recommended_tests()` no longer add `{processx}` to the `DESCRIPTION` (#710) -+ `bundle_resource()` does not include empty stylesheet anymore (#689, @erikvona) +- `bundle_resource()` does not include empty stylesheet anymore (#689, @erikvona) ## Internal changes -+ Create `{golem}` is more robust and now comes with an `overwrite` argument (#777) +- Create `{golem}` is more robust and now comes with an `overwrite` argument (#777) -+ `{testthat}` and `{rlang}` are no longer hard dependencies (#742) +- `{testthat}` and `{rlang}` are no longer hard dependencies (#742) # golem 0.3.1 (CRAN Version) @@ -139,316 +134,315 @@ Update in the tests for CRAN (skip not installed + examples). ### `add_*` -+ You can now create a skeleton for a Shiny input binding using the `golem::add_js_binding("name")` function (#452, @DivadNojnarg) +- You can now create a skeleton for a Shiny input binding using the `golem::add_js_binding("name")` function (#452, @DivadNojnarg) -+ You can now create a skeleton for a Shiny output binding using the `golem::add_js_output_binding("name")` function (@DivadNojnarg) +- You can now create a skeleton for a Shiny output binding using the `golem::add_js_output_binding("name")` function (@DivadNojnarg) -+ `add_html_template()` creates an htmlTemplate. +- `add_html_template()` creates an htmlTemplate. ### `use_*` -+ `use_external_file()` allows to add any file to the `www` folder, `use_external_css_file()`, `use_external_html_template()`, and `use_external_js_file()` will download them from a URL (#295, #491). +- `use_external_file()` allows to add any file to the `www` folder, `use_external_css_file()`, `use_external_html_template()`, and `use_external_js_file()` will download them from a URL (#295, #491). -+ `use_internal_css_file()`, `use_internal_file()`, `use_internal_html_template()`, `use_internal_js_file()` functions allow to any file from the current computer to the `www` folder (@KasperThystrup, #529) +- `use_internal_css_file()`, `use_internal_file()`, `use_internal_html_template()`, `use_internal_js_file()` functions allow to any file from the current computer to the `www` folder (@KasperThystrup, #529) ### Tests helper -+ `expect_running()` expects the current shiny app to be running. +- `expect_running()` expects the current shiny app to be running. ### Hooks -+ Every `{golem}` project now have a `project_hook` that is launched after the project creation. +- Every `{golem}` project now have a `project_hook` that is launched after the project creation. -+ `module_template()` is the default function for `{golem}` module creation. Users will now be able to define a custom `module_template()` function for `add_module()`, allowing to extend `{golem}` with your own module creation function. See ?golem::module_template for more info (#365) +- `module_template()` is the default function for `{golem}` module creation. Users will now be able to define a custom `module_template()` function for `add_module()`, allowing to extend `{golem}` with your own module creation function. See ?golem::module_template for more info (#365) -+ `add_js_` and `add_css_` functions now have a template function, allowing to pass a file constructor. +- `add_js_` and `add_css_` functions now have a template function, allowing to pass a file constructor. ### Misc -+ `is_running()` checks if the current running application is a `{golem}` based application (#366) +- `is_running()` checks if the current running application is a `{golem}` based application (#366) -+ `utils_ui.R` now contains a "make_action_button()" function (#457, @DivadNojnarg) +- `utils_ui.R` now contains a "make_action_button()" function (#457, @DivadNojnarg) -+ `run_dev()` launches the `run_dev.R` script (#478, @KoderKow) +- `run_dev()` launches the `run_dev.R` script (#478, @KoderKow) -+ `run_dev()` performs a check on golem name. +- `run_dev()` performs a check on golem name. -+ `sanity_check()` function has been added to check for any 'browser()' or commented #TODO / #TOFIX / #BUG in the code (#1354 @Swechhya) +- `sanity_check()` function has been added to check for any 'browser()' or commented #TODO / #TOFIX / #BUG in the code (#1354 @Swechhya) ## New features -+ The modules are now created with the new skeleton when the installed version of `{shiny}` is >= 1.5.0. +- The modules are now created with the new skeleton when the installed version of `{shiny}` is >= 1.5.0. -+ `use_external_*()` function don't open files by default (#404) +- `use_external_*()` function don't open files by default (#404) -+ `use_recommended_tests*()` now calls ` use_spell_check()` (#430) +- `use_recommended_tests*()` now calls ` use_spell_check()` (#430) -+ The `02_dev.R` now includes more CI links +- The `02_dev.R` now includes more CI links -+ `golem::expect_running()` is now bundled in default tests +- `golem::expect_running()` is now bundled in default tests -+ Default tests now test for functions formals (#437) +- Default tests now test for functions formals (#437) -+ You can now pass arguments to internal `roxygenise()` & `load_all()` (#467) +- You can now pass arguments to internal `roxygenise()` & `load_all()` (#467) -+ `Bundle_resources()` now handle subfolders (#446) +- `Bundle_resources()` now handle subfolders (#446) -+ `run_app()` now includes the default arguments of `shinyApp()` (#254, @chasemc) +- `run_app()` now includes the default arguments of `shinyApp()` (#254, @chasemc) -+ `create_golem()` now adds strict dependency versions (#466) +- `create_golem()` now adds strict dependency versions (#466) -+ `{golem}` app now comes with a meta tags "app-builder", which default to "golem", and that can be changed or turn off in `bundle_resources()`. +- `{golem}` app now comes with a meta tags "app-builder", which default to "golem", and that can be changed or turn off in `bundle_resources()`. -+ `with_golem_options` can now explicit calls `print` on the `app` object, solving some issues with benchmarking the application. This explicit print can be turned off by setting `print` to FALSE in `with_golem_options` (#148) +- `with_golem_options` can now explicit calls `print` on the `app` object, solving some issues with benchmarking the application. This explicit print can be turned off by setting `print` to FALSE in `with_golem_options` (#148) -+ `dockerignore` is now available. +- `dockerignore` is now available. -+ The `add_helpers` and `add_utils` now have roxygen comments (Richard Pilbery, #330) +- The `add_helpers` and `add_utils` now have roxygen comments (Richard Pilbery, #330) -+ `dev/03_dev.R` now has `devtools::build()` (#603) +- `dev/03_dev.R` now has `devtools::build()` (#603) -+ `detach_all_attached()` is now silent (#605) +- `detach_all_attached()` is now silent (#605) ## Soft deprecated -+ `add_ui_server_files()` is now signaled as deprecated. Please comment on https://github.com/ThinkR-open/golem/issues/445 if you want it to be kept inside the package +- `add_ui_server_files()` is now signaled as deprecated. Please comment on https://github.com/ThinkR-open/golem/issues/445 if you want it to be kept inside the package ## Breaking changes -+ `add_dockerfile*` function now return the `{dockerfiler}` object instead of the path to it. It allows to modify the Dockerfile object programmatically. (#493) +- `add_dockerfile*` function now return the `{dockerfiler}` object instead of the path to it. It allows to modify the Dockerfile object programmatically. (#493) -+ The `get_golem_config` now first look for a `GOLEM_CONFIG_ACTIVE` before looking for `R_CONFIG_ACTIVE` (#563) +- The `get_golem_config` now first look for a `GOLEM_CONFIG_ACTIVE` before looking for `R_CONFIG_ACTIVE` (#563) ## Bug fix -+ `add_` functions no longer append to file if it already exists (#393) +- `add_` functions no longer append to file if it already exists (#393) -+ `config::get()` is no longer exported to prevent namespace conflicts with `base::get()` +- `config::get()` is no longer exported to prevent namespace conflicts with `base::get()` -+ fixed issue with favicon when package is built (#387) +- fixed issue with favicon when package is built (#387) -+ `use_external_*()` function don't add ext if already there (#405) +- `use_external_*()` function don't add ext if already there (#405) -+ `create_golem` function does not modify any existing file (#423, @antoine-sachet) +- `create_golem` function does not modify any existing file (#423, @antoine-sachet) -+ `add_resources_path()` now correctly handles empty folder (#395) +- `add_resources_path()` now correctly handles empty folder (#395) -+ test for app launching is now skipped if not interactive() +- test for app launching is now skipped if not interactive() -+ `add_utils` and `add_fct` now print to the console (#427, @novica) +- `add_utils` and `add_fct` now print to the console (#427, @novica) -+ Multiple CRAN repo are now correctly passed to the Dockerfile (#462) +- Multiple CRAN repo are now correctly passed to the Dockerfile (#462) -+ app_config, DESC and golem-config.yml are now updated whenever you change the name of the package using a golem function (#469 ) +- app_config, DESC and golem-config.yml are now updated whenever you change the name of the package using a golem function (#469 ) -+ `test_recommended` now work in every case (hopefully) +- `test_recommended` now work in every case (hopefully) -- `usethis::use_mit_license` does not have the `name` argument anymore so if fits new version of `{usethis}` (#594) +* `usethis::use_mit_license` does not have the `name` argument anymore so if fits new version of `{usethis}` (#594) -- Typo fix preventing `invoke_js("prompt")` and `invoke_js("confirm")` to work (#606) +* Typo fix preventing `invoke_js("prompt")` and `invoke_js("confirm")` to work (#606) ## Internal changes -+ `document_and_reload()` now has `export_all = FALSE,helpers = FALSE,attach_testthat = FALSE`, allowing the function to behave more closely to what library() does (#399) +- `document_and_reload()` now has `export_all = FALSE,helpers = FALSE,attach_testthat = FALSE`, allowing the function to behave more closely to what library() does (#399) -+ Dockerfile generation now removes the copied file and tar.gz +- Dockerfile generation now removes the copied file and tar.gz # golem 0.2.1 ## New functions -+ `add_dockerfile()` was completely refactored. It now starts from r-ver, uses explicit package versions from you local machine, and tries to set as much System Requirements as possible by using `{sysreq}`, and parses and installs the Remotes tag from the DESCRIPTION (#189, #175) - -+ `add_dockerfile()` allow now to directly use the source of the package by mounting the source folder in the container and running `remotes::install_local()` +- `add_dockerfile()` was completely refactored. It now starts from r-ver, uses explicit package versions from you local machine, and tries to set as much System Requirements as possible by using `{sysreq}`, and parses and installs the Remotes tag from the DESCRIPTION (#189, #175) -+ `add_dockerfile()` now builds the tar.gz (#273) +- `add_dockerfile()` allow now to directly use the source of the package by mounting the source folder in the container and running `remotes::install_local()` -+ `add_fct` and `add_utils` add new files in your R folder that can hold utils and functions (#123). +- `add_dockerfile()` now builds the tar.gz (#273) -+ We switched from `shiny::addResourcePath()` to `golem::add_resource_path()`, which doesn't fail if the folder is empty (#223). +- `add_fct` and `add_utils` add new files in your R folder that can hold utils and functions (#123). -+ New JavaScript functions to use alert, prompt and confirm (#108, @zwycl) +- We switched from `shiny::addResourcePath()` to `golem::add_resource_path()`, which doesn't fail if the folder is empty (#223). -+ `use_external_js_file` and `use_external_css_file` are designed to download .js and .css file off the web to the appropriate directory (#130, @zwycl) +- New JavaScript functions to use alert, prompt and confirm (#108, @zwycl) +- `use_external_js_file` and `use_external_css_file` are designed to download .js and .css file off the web to the appropriate directory (#130, @zwycl) ## New features -+ `{golem}` now comes with an internal config file. Please refer to the `config` Vignette for more information. +- `{golem}` now comes with an internal config file. Please refer to the `config` Vignette for more information. -+ `bundle_resources()` comes with every new app and bundles all the css and js files you put inside the `inst/app/www` folder, by matchine the file extension. +- `bundle_resources()` comes with every new app and bundles all the css and js files you put inside the `inst/app/www` folder, by matchine the file extension. -+ There is now an `app_sys()` function, which is a wrapper around `system.file(..., package = "myapp")` (#207, @novica) +- There is now an `app_sys()` function, which is a wrapper around `system.file(..., package = "myapp")` (#207, @novica) -+ `document_and_reload()` now stops when it fails, and returns an explicit failure message (#157) +- `document_and_reload()` now stops when it fails, and returns an explicit failure message (#157) -+ You can now create a golem without any comment (#171, @ArthurData) +- You can now create a golem without any comment (#171, @ArthurData) -+ The default `app_ui()` now has a `request` parameter, to natively handle bookmarking. +- The default `app_ui()` now has a `request` parameter, to natively handle bookmarking. -+ `document_and_reload()` now stops when it fails, and returns an explicit failure message (#157). It also uses `get_golem_wd()` as a default path, to be consistent with the rest of `{golem}` (#219, @j450h1) +- `document_and_reload()` now stops when it fails, and returns an explicit failure message (#157). It also uses `get_golem_wd()` as a default path, to be consistent with the rest of `{golem}` (#219, @j450h1) -+ `add_module` now allows to create and `fct_` and an `utils_` file (#154, @novica) +- `add_module` now allows to create and `fct_` and an `utils_` file (#154, @novica) -+ `golem::detach_all_attached()` is now silent (#186, @annakau) +- `golem::detach_all_attached()` is now silent (#186, @annakau) -+ There is now a series of addins for going to a specific golem file (#212, @novica), and also to wrap a selected text into `ns()` (#143, @kokbent) +- There is now a series of addins for going to a specific golem file (#212, @novica), and also to wrap a selected text into `ns()` (#143, @kokbent) -+ Creation of a golem project is now a little bit more talkative (#63, @novica) +- Creation of a golem project is now a little bit more talkative (#63, @novica) -+ golem apps now have a title tag in the header by default, (#172, @novica) +- golem apps now have a title tag in the header by default, (#172, @novica) -+ The `rsconnect` folder is now added to `.Rbuildignore` (#244) +- The `rsconnect` folder is now added to `.Rbuildignore` (#244) -+ `devtools::test()` in 03_deploy.R is now `devtools::check()` +- `devtools::test()` in 03_deploy.R is now `devtools::check()` -+ modules bow have a placeholder for content +- modules bow have a placeholder for content -+ Dev scripts have been rewritten and rerordered a litte bit +- Dev scripts have been rewritten and rerordered a litte bit ## Breaking changes -+ `invoke_js()` now takes a list of elements to send to JS (through `...`) instead of a vector (#155, @zwycl) +- `invoke_js()` now takes a list of elements to send to JS (through `...`) instead of a vector (#155, @zwycl) -+ `get_dependencies` was removed from this package, please use `desc::desc_get_deps()` instead (#251) +- `get_dependencies` was removed from this package, please use `desc::desc_get_deps()` instead (#251) -+ `{golem}` now uses `here::here()` to determine the default working directory (#287) +- `{golem}` now uses `here::here()` to determine the default working directory (#287) -+ Modules used to be exported by default. You now have to specify it when creating the modules (#144) +- Modules used to be exported by default. You now have to specify it when creating the modules (#144) -+ `run_app()` is no longer explicitely namespaced in the run_dev script (#267) +- `run_app()` is no longer explicitely namespaced in the run_dev script (#267) -+ JavaScript files now default to having `$(document).ready()` (#227) +- JavaScript files now default to having `$(document).ready()` (#227) -+ Every filesystem manipulation is now done with `{fs}`. That should be pretty transparent for most users but please open an issue if it causes problem (#285) +- Every filesystem manipulation is now done with `{fs}`. That should be pretty transparent for most users but please open an issue if it causes problem (#285) ## Bug fix -+ The Dockerfile is now correctly added to .Rbuildignore (#81) +- The Dockerfile is now correctly added to .Rbuildignore (#81) -+ The dockerfile for shinyproxy no longer has a typo (#156, @fmmattioni) +- The dockerfile for shinyproxy no longer has a typo (#156, @fmmattioni) -+ `normalizePath()` now has a correct winlash (@kokbent) +- `normalizePath()` now has a correct winlash (@kokbent) -+ spellcheck in files (@privefl) +- spellcheck in files (@privefl) -+ Message to link to `golem_add_external_resources()` is now conditional to R being in a golem project (#167, @novica) +- Message to link to `golem_add_external_resources()` is now conditional to R being in a golem project (#167, @novica) -+ Better error on missing name in add_*, (#120, @novica) +- Better error on missing name in add\_\*, (#120, @novica) -+ When adding file, the extension is now ignored if provided by the user (#231) +- When adding file, the extension is now ignored if provided by the user (#231) -+ The dots R/run_app.R are now documented by default (#243) +- The dots R/run_app.R are now documented by default (#243) -+ Bug fix of the pkgdown website (#180) +- Bug fix of the pkgdown website (#180) -+ `{golem}` now correctly handles command line creation of projet inside the current directory (#248) +- `{golem}` now correctly handles command line creation of projet inside the current directory (#248) -+ The test are now more robust when it comes to random name generation (#281) +- The test are now more robust when it comes to random name generation (#281) ## Internal changes -+ We no longer depend on `{stringr}` (#201, @TomerPacific) +- We no longer depend on `{stringr}` (#201, @TomerPacific) -+ get_golem_wd() is now used everywhere in `{golem}` (#237, @felixgolcher) +- get_golem_wd() is now used everywhere in `{golem}` (#237, @felixgolcher) -# golem 0.1.0 - CRAN release candidate, v2 +# golem 0.1.0 - CRAN release candidate, v2 ## New Functions -+ `get_golem_wd` allows to print the current golem working directory, and `set_golem_wd` to change it. +- `get_golem_wd` allows to print the current golem working directory, and `set_golem_wd` to change it. ## Breaking changes -+ In order to work, the functions creating files need a `golem.wd`. This working directory is set by `set_golem_options` or the first time you create a file. It default to `"."`, the current directory. +- In order to work, the functions creating files need a `golem.wd`. This working directory is set by `set_golem_options` or the first time you create a file. It default to `"."`, the current directory. -+ Changes in the name of the args in `set_golem_options`: `pkg_path` is now `golem_wd`, `pkg_name` is now `golem_name`, `pkg_version` is now `golem_version` +- Changes in the name of the args in `set_golem_options`: `pkg_path` is now `golem_wd`, `pkg_name` is now `golem_name`, `pkg_version` is now `golem_version` ## Internal changes -+ The `installed.packages()` function is no longer used. +- The `installed.packages()` function is no longer used. -+ Every filesystem manipulation is now done with `{fs}` (#285) +- Every filesystem manipulation is now done with `{fs}` (#285) # golem 0.0.1.9999 - CRAN release candidate ## Changes in the way run_app and deploy files are build -+ There is now a unique framework for run_app, that allows to deploy anywhere and can accept arguments. These arguments can then be retrieved with `get_golem_options()`. +- There is now a unique framework for run_app, that allows to deploy anywhere and can accept arguments. These arguments can then be retrieved with `get_golem_options()`. > See https://rtask.thinkr.fr/blog/shinyapp-runapp-shinyappdir-difference/ ## Breaking Changes -+ There is no need for `ui.R` and `server.R` to exist by default. Removed. Can be recreated with `add_ui_server_files()` +- There is no need for `ui.R` and `server.R` to exist by default. Removed. Can be recreated with `add_ui_server_files()` ## New function -+ There is now `add_shinyserver_file` & `add_shinyappsio_file`, #40 -+ `add_ui_server_files()` creates an ui & server.R files. +- There is now `add_shinyserver_file` & `add_shinyappsio_file`, #40 +- `add_ui_server_files()` creates an ui & server.R files. ## Small functions updates -+ Functions that create file(s) now automatically create folder if it's not there. Can be prevented with `dir_create = FALSE` -+ Functions that create file(s) can now be prevented from opening with `open = FALSE`, #75 -+ We have made explicit how to add external files (css & js) to the app, #78 -+ Launch test is now included in the default tests #48 +- Functions that create file(s) now automatically create folder if it's not there. Can be prevented with `dir_create = FALSE` +- Functions that create file(s) can now be prevented from opening with `open = FALSE`, #75 +- We have made explicit how to add external files (css & js) to the app, #78 +- Launch test is now included in the default tests #48 # golem 0.0.1.6000+ ## Changes -* `create_golem()` now switch to the newly created project -* `use_git()` is not listed in `dev/01_start.R` +- `create_golem()` now switch to the newly created project +- `use_git()` is not listed in `dev/01_start.R` ## Breaking changes -* Renamed `add_rconnect_file()` to `add_rstudioconnect_file()` -* Renamed `create_shiny_template()` to `create_golem()` -* Renamed `js()` to `activate_js()` -* Renamed `use_recommended_dep()` to `use_recommended_deps()` +- Renamed `add_rconnect_file()` to `add_rstudioconnect_file()` +- Renamed `create_shiny_template()` to `create_golem()` +- Renamed `js()` to `activate_js()` +- Renamed `use_recommended_dep()` to `use_recommended_deps()` ## New functions -* `invoke_js()` allows to call JS functions from the server side. #52 +- `invoke_js()` allows to call JS functions from the server side. #52 # golem 0.0.1.5000 ## Changes -* The dev files are now split in three - start / dev / deploy +- The dev files are now split in three - start / dev / deploy -* Every function that adds a file now check if the file already exists, and ask the user if they want to overwrite it (#15) +- Every function that adds a file now check if the file already exists, and ask the user if they want to overwrite it (#15) -* Every module is now named mod_x_ui / mod_x_server, for consistency. +- Every module is now named mod_x_ui / mod_x_server, for consistency. -* You can now create package with "illegal" names, using the command line `golem::create_shiny_template()`. #18 +- You can now create package with "illegal" names, using the command line `golem::create_shiny_template()`. #18 -* `add_browser_button()` is now named `browser_button()`, so that all the `add_*` function are only reserved for function adding files to the `golem`. +- `add_browser_button()` is now named `browser_button()`, so that all the `add_*` function are only reserved for function adding files to the `golem`. -+ `add_*_files` now check if the folder exists, if not suggests to create it. #36 +* `add_*_files` now check if the folder exists, if not suggests to create it. #36 ## New functions -* You now have a `browser_dev()` function that behaves like `warning_dev` and friends. #46 +- You now have a `browser_dev()` function that behaves like `warning_dev` and friends. #46 -* Added `set_golem_options()` to add local options used internally by {golem} && added it to the `01_start.R`. #49 +- Added `set_golem_options()` to add local options used internally by {golem} && added it to the `01_start.R`. #49 -* Added `add_dockerfile()` to create a Dockerfile from a DESCRIPTION. +- Added `add_dockerfile()` to create a Dockerfile from a DESCRIPTION. -* Added `add_dockerfile_shinyproxy()` to create a Dockerfile from a DESCRIPTION, to be used in Shiny Proxy. +- Added `add_dockerfile_shinyproxy()` to create a Dockerfile from a DESCRIPTION, to be used in Shiny Proxy. -* Added `add_dockerfile_heroku()` to create a Dockerfile from a DESCRIPTION, to be used with Heroku. +- Added `add_dockerfile_heroku()` to create a Dockerfile from a DESCRIPTION, to be used with Heroku. -* `add_css_file()`, `add_js_file()` and `add_js_handler()` create a CSS, JS, and JS with Shiny custom handler files. +- `add_css_file()`, `add_js_file()` and `add_js_handler()` create a CSS, JS, and JS with Shiny custom handler files. ## Removed -* `use_utils_prod` is now included in golem so you don't have to explicitly include the functions. +- `use_utils_prod` is now included in golem so you don't have to explicitly include the functions. ## Docs -* Golem now has four vignettes +- Golem now has four vignettes # golem 0.0.1.0002 @@ -456,6 +450,6 @@ Last round of functions, and some documentation cleanup. # golem 0.0.0.9000 -* Moved from {shinytemplate} to {golem} +- Moved from {shinytemplate} to {golem} -* Added a `NEWS.md` file to track changes to the package. +- Added a `NEWS.md` file to track changes to the package. diff --git a/R/add_dockerfiles_renv.R b/R/add_dockerfiles_renv.R index 9c38a977..a1b6a42e 100644 --- a/R/add_dockerfiles_renv.R +++ b/R/add_dockerfiles_renv.R @@ -1,27 +1,25 @@ add_dockerfile_with_renv_ <- function( - source_folder = ".", - lockfile = NULL, - output_dir = fs::path(tempdir(), "deploy"), - distro = "focal", - FROM = "rocker/verse", - AS = NULL, - sysreqs = TRUE, - repos = c(CRAN = "https://cran.rstudio.com/"), - expand = FALSE, - extra_sysreqs = NULL, - update_tar_gz = TRUE, - document = FALSE, - ... - # build_golem_from_source = TRUE, -) { - - if (is.null(lockfile)) { - rlang::check_installed( - c("renv","attachment"), - reason = "to build a Dockerfile with automatic renv.lock creation. Use the `lockfile` parameter to pass your own `renv.lock` file." - ) - - } + source_folder = ".", + lockfile = NULL, + output_dir = fs::path(tempdir(), "deploy"), + distro = "focal", + FROM = "rocker/verse", + AS = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + extra_sysreqs = NULL, + update_tar_gz = TRUE, + document = FALSE, + ... + # build_golem_from_source = TRUE, + ) { + if (is.null(lockfile)) { + rlang::check_installed( + c("renv", "attachment"), + reason = "to build a Dockerfile with automatic renv.lock creation. Use the `lockfile` parameter to pass your own `renv.lock` file." + ) + } # Small hack to prevent warning from rlang::lang() in tests @@ -38,10 +36,7 @@ add_dockerfile_with_renv_ <- function( } if (is.null(lockfile)) { - - - if ( isTRUE(document) ){ - + if (isTRUE(document)) { cli_cat_line("You set `document = TRUE` and you did not pass your own renv.lock file,") cli_cat_line("as a consequence {golem} will use `attachment::att_amend_desc()` to update your ") cli_cat_line("DESCRIPTION file before creating the renv.lock file") @@ -57,14 +52,19 @@ add_dockerfile_with_renv_ <- function( lockfile <- attachment_create_renv_for_prod( path = source_folder, - check_if_suggests_is_installed = FALSE, document = document, + check_if_suggests_is_installed = FALSE, document = document, output = file.path(output_dir, "renv.lock.prod"), ... ) } - file.copy(from = lockfile, to = output_dir) - socle <- dockerfiler_dock_from_renv( + fs_file_copy( + path = lockfile, + new_path = output_dir, + overwrite = TRUE + ) + + socle <- dockerfiler::dock_from_renv( lockfile = lockfile, distro = distro, FROM = FROM, @@ -78,8 +78,7 @@ add_dockerfile_with_renv_ <- function( socle$write(as = file.path(output_dir, "Dockerfile_base")) - my_dock <- dockerfiler::Dockerfile$new(FROM = tolower(paste0(golem::get_golem_name(), "_base"))) - + my_dock <- dockerfiler::Dockerfile$new(FROM = tolower(tolower(paste0(golem::get_golem_name(), "_base")))) my_dock$COPY("renv.lock.prod", "renv.lock") @@ -155,24 +154,23 @@ add_dockerfile_with_renv_ <- function( #' @rdname dockerfiles #' @export add_dockerfile_with_renv <- function( - source_folder = ".", - lockfile = NULL, - output_dir = fs::path(tempdir(), "deploy"), - distro = "focal", - from = "rocker/verse", - as = NULL, - sysreqs = TRUE, - port = 80, - host = "0.0.0.0", - repos = c(CRAN = "https://cran.rstudio.com/"), - expand = FALSE, - open = TRUE, - document = TRUE, - extra_sysreqs = NULL, - update_tar_gz = TRUE, - dockerfile_cmd = NULL, - ... -) { + source_folder = ".", + lockfile = NULL, + output_dir = fs::path(tempdir(), "deploy"), + distro = "focal", + from = "rocker/verse", + as = NULL, + sysreqs = TRUE, + port = 80, + host = "0.0.0.0", + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + open = TRUE, + document = TRUE, + extra_sysreqs = NULL, + update_tar_gz = TRUE, + dockerfile_cmd = NULL, + ...) { base_dock <- add_dockerfile_with_renv_( source_folder = source_folder, lockfile = lockfile, @@ -210,8 +208,8 @@ add_dockerfile_with_renv <- function( docker build -f Dockerfile --progress=plain -t %s . docker run -p %s:%s %s # then go to 127.0.0.1:%s", - tolower(paste0(golem::get_golem_name(), "_base")), - tolower(paste0(golem::get_golem_name(), ":latest")), + paste0(golem::get_golem_name(), "_base"), + paste0(golem::get_golem_name(), ":latest"), port, port, tolower(paste0(golem::get_golem_name(), ":latest")), @@ -231,21 +229,20 @@ docker run -p %s:%s %s #' @export #' @export add_dockerfile_with_renv_shinyproxy <- function( - source_folder = ".", - lockfile = NULL, - output_dir = fs::path(tempdir(), "deploy"), - distro = "focal", - from = "rocker/verse", - as = NULL, - sysreqs = TRUE, - repos = c(CRAN = "https://cran.rstudio.com/"), - expand = FALSE, - extra_sysreqs = NULL, - open = TRUE, - document = TRUE, - update_tar_gz = TRUE, - ... -) { + source_folder = ".", + lockfile = NULL, + output_dir = fs::path(tempdir(), "deploy"), + distro = "focal", + from = "rocker/verse", + as = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + extra_sysreqs = NULL, + open = TRUE, + document = TRUE, + update_tar_gz = TRUE, + ...) { add_dockerfile_with_renv( source_folder = source_folder, lockfile = lockfile, @@ -275,21 +272,20 @@ add_dockerfile_with_renv_shinyproxy <- function( #' @export #' @export add_dockerfile_with_renv_heroku <- function( - source_folder = ".", - lockfile = NULL, - output_dir = fs::path(tempdir(), "deploy"), - distro = "focal", - from = "rocker/verse", - as = NULL, - sysreqs = TRUE, - repos = c(CRAN = "https://cran.rstudio.com/"), - expand = FALSE, - extra_sysreqs = NULL, - open = TRUE, - document = TRUE, - update_tar_gz = TRUE, - ... -) { + source_folder = ".", + lockfile = NULL, + output_dir = fs::path(tempdir(), "deploy"), + distro = "focal", + from = "rocker/verse", + as = NULL, + sysreqs = TRUE, + repos = c(CRAN = "https://cran.rstudio.com/"), + expand = FALSE, + extra_sysreqs = NULL, + open = TRUE, + document = TRUE, + update_tar_gz = TRUE, + ...) { add_dockerfile_with_renv( source_folder = source_folder, lockfile = lockfile, diff --git a/R/utils.R b/R/utils.R index ef475bc1..908285ba 100644 --- a/R/utils.R +++ b/R/utils.R @@ -391,6 +391,48 @@ yesno <- function(...) { menu(c("Yes", "No")) == 1 } + +# Checking that a package is installed +check_is_installed <- function( + pak, + ... +) { + if ( + !requireNamespace(pak, ..., quietly = TRUE) + ) { + stop( + sprintf( + "The {%s} package is required to run this function.\nYou can install it with `install.packages('%s')`.", + pak, + pak + ), + call. = FALSE + ) + } +} + +required_version <- function( + pak, + version +) { + if ( + utils::packageVersion(pak) < version + ) { + stop( + sprintf( + "This function require the version '%s' of the {%s} package.\nYou can update with `install.packages('%s')`.", + version, + pak, + pak + ), + call. = FALSE + ) + } +} + + + + add_sass_code <- function(where, dir, name) { if (fs_file_exists(where)) { if (fs_file_exists("dev/run_dev.R")) { From 1e79e54f0225c781f92756c575759ff674fd5a21 Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 10 Mar 2023 11:51:58 +0100 Subject: [PATCH 55/55] fix: run the function instead of $ its body --- R/add_dockerfiles_renv.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/add_dockerfiles_renv.R b/R/add_dockerfiles_renv.R index 8764c164..24afc09f 100644 --- a/R/add_dockerfiles_renv.R +++ b/R/add_dockerfiles_renv.R @@ -78,7 +78,7 @@ add_dockerfile_with_renv_ <- function( socle$write(as = file.path(output_dir, "Dockerfile_base")) - my_dock <- dockerfiler_Dockerfile$new(FROM = tolower(tolower(paste0(golem::get_golem_name(), "_base")))) + my_dock <- dockerfiler_Dockerfile()$new(FROM = tolower(tolower(paste0(golem::get_golem_name(), "_base")))) my_dock$COPY("renv.lock.prod", "renv.lock") @@ -209,7 +209,7 @@ docker build -f Dockerfile --progress=plain -t %s . docker run -p %s:%s %s # then go to 127.0.0.1:%s", tolower(paste0(golem::get_golem_name(), "_base")), - tolower( paste0(golem::get_golem_name(), ":latest")), + tolower(paste0(golem::get_golem_name(), ":latest")), port, port, tolower(paste0(golem::get_golem_name(), ":latest")),