Skip to content

Commit

Permalink
fix: set default value for argument name before using it
Browse files Browse the repository at this point in the history
- the order needs a change at some places: first set a default value when name argument is missing
    - only then call check_name_length() to avoid errors of the type:
    "argument "name" is missing, with no default"
- also, to avoid RStudio and other IDEs linting a missing argument, provide a default value "NULL" for argument  'name'

Refs: ThinkR-open#1060
  • Loading branch information
ilyaZar committed Jul 5, 2023
1 parent 89b04ab commit 372d3aa
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions R/use_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' @return The path to the file, invisibly.
use_external_js_file <- function(
url,
name,
name = NULL,
pkg = get_golem_wd(),
dir = "inst/app/www",
open = FALSE,
Expand Down Expand Up @@ -85,7 +85,7 @@ use_external_js_file <- function(
#' @rdname use_files
use_external_css_file <- function(
url,
name,
name = NULL,
pkg = get_golem_wd(),
dir = "inst/app/www",
open = FALSE,
Expand Down Expand Up @@ -211,18 +211,18 @@ use_external_html_template <- function(
#' @rdname use_files
use_external_file <- function(
url,
name,
name = NULL,
pkg = get_golem_wd(),
dir = "inst/app/www",
open = FALSE,
dir_create = TRUE
) {
check_name_length(name)

if (missing(name)) {
name <- basename(url)
}

check_name_length(name)

old <- setwd(fs_path_abs(pkg))
on.exit(setwd(old))
Expand Down Expand Up @@ -260,20 +260,21 @@ use_external_file <- function(
#' @rdname use_files
use_internal_js_file <- function(
path,
name,
name = NULL,
pkg = get_golem_wd(),
dir = "inst/app/www",
open = FALSE,
dir_create = TRUE
) {
check_name_length(name)
old <- setwd(fs_path_abs(pkg))
on.exit(setwd(old))

if (missing(name)) {
name <- basename(path)
}

check_name_length(name)

name <- file_path_sans_ext(name)
new_file <- sprintf("%s.js", name)

Expand Down Expand Up @@ -325,13 +326,12 @@ use_internal_js_file <- function(
#' @rdname use_files
use_internal_css_file <- function(
path,
name,
name = NULL,
pkg = get_golem_wd(),
dir = "inst/app/www",
open = FALSE,
dir_create = TRUE
) {
check_name_length(name)

old <- setwd(fs_path_abs(pkg))
on.exit(setwd(old))
Expand All @@ -340,6 +340,8 @@ use_internal_css_file <- function(
name <- basename(path)
}

check_name_length(name)

name <- file_path_sans_ext(name)
new_file <- sprintf("%s.css", name)

Expand Down Expand Up @@ -449,7 +451,7 @@ use_internal_html_template <- function(
#' @rdname use_files
use_internal_file <- function(
path,
name,
name = NULL,
pkg = get_golem_wd(),
dir = "inst/app/www",
open = FALSE,
Expand Down

0 comments on commit 372d3aa

Please sign in to comment.