Skip to content

Commit

Permalink
remove usethis and fs functions
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Jan 9, 2023
1 parent a9e8be3 commit a96d166
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 0 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Imports:
Suggests:
bookdown,
crayon,
fs,
httr (>= 1.2.1),
jsonlite,
mockery,
Expand All @@ -48,7 +47,6 @@ Suggests:
testthat (>= 3.0.0),
tibble,
tufte,
usethis,
withr (>= 2.5.0)
VignetteBuilder:
knitr
Expand Down
23 changes: 21 additions & 2 deletions R/use_lintr.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,31 @@ use_lintr <- function(path = ".", type = c("tidyverse", "full")) {
write.dcf(the_config, config_file, width = Inf)

# If this is an R package and if available, add .lintr file to .Rbuildignore
if (file.exists("DESCRIPTION")) {
if (file.exists("DESCRIPTION") && file.exists(".Rbuildignore")) {
try(
usethis::use_build_ignore(fs::path_rel(config_file)),
add_build_ignore(config_file),
silent = TRUE
)
}

invisible(config_file)
}

add_build_ignore <- function(path) {
path_build_ignore <- ".Rbuildignore"
existing_lines <- readLines(path_build_ignore, encoding = "UTF-8", warn = FALSE)

escape_path <- gsub("^\\./", "", path)
escape_path <- gsub("\\.", "\\\\.", escape_path)
escape_path <- gsub("/$", "", escape_path)
escape_path <- paste0("^", escape_path, "$")

new_lines <- c(existing_lines, setdiff(escape_path, existing_lines))

con <- file(path_build_ignore, open = "wb", encoding = "utf-8")
writeLines(enc2utf8(new_lines), con, useBytes = TRUE)

message("Add '", escape_path, "' to ", path_build_ignore)

invisible(NULL)
}

0 comments on commit a96d166

Please sign in to comment.