@@ -45,12 +45,31 @@ use_lintr <- function(path = ".", type = c("tidyverse", "full")) {
45
45
write.dcf(the_config , config_file , width = Inf )
46
46
47
47
# If this is an R package and if available, add .lintr file to .Rbuildignore
48
- if (file.exists(" DESCRIPTION" )) {
48
+ if (file.exists(" DESCRIPTION" ) && file.exists( " .Rbuildignore " ) ) {
49
49
try(
50
- usethis :: use_build_ignore( fs :: path_rel( config_file ) ),
50
+ add_build_ignore( config_file ),
51
51
silent = TRUE
52
52
)
53
53
}
54
54
55
55
invisible (config_file )
56
56
}
57
+
58
+ add_build_ignore <- function (path ) {
59
+ path_build_ignore <- " .Rbuildignore"
60
+ existing_lines <- readLines(path_build_ignore , encoding = " UTF-8" , warn = FALSE )
61
+
62
+ escape_path <- gsub(" ^\\ ./" , " " , path )
63
+ escape_path <- gsub(" \\ ." , " \\\\ ." , escape_path )
64
+ escape_path <- gsub(" /$" , " " , escape_path )
65
+ escape_path <- paste0(" ^" , escape_path , " $" )
66
+
67
+ new_lines <- c(existing_lines , setdiff(escape_path , existing_lines ))
68
+
69
+ con <- file(path_build_ignore , open = " wb" , encoding = " utf-8" )
70
+ writeLines(enc2utf8(new_lines ), con , useBytes = TRUE )
71
+
72
+ message(" Add '" , escape_path , " ' to " , path_build_ignore )
73
+
74
+ invisible (NULL )
75
+ }
0 commit comments