@@ -45,12 +45,30 @@ 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 <- xfun :: read_utf8(path_build_ignore )
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
+ xfun :: write_utf8(new_lines , path_build_ignore )
70
+
71
+ message(" Add '" , escape_path , " ' to " , path_build_ignore )
72
+
73
+ invisible (NULL )
74
+ }
0 commit comments