Skip to content

Commit ce537b1

Browse files
authored
Merge pull request #83 from stan-dev/fix-noedit-in-config
fix r cmd check note about #! interpreter line
2 parents 4a8a402 + 7cc2af0 commit ce537b1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

R/rstan_package_utils.R

+8-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
noedit_msg <- .rstantools_noedit(dest_file)
7373
has_file <- file.exists(dest_file) # check if file exists
7474
# check if existing file is a stan file
75-
is_stanfile <- has_file && (readLines(dest_file, n = 1) == noedit_msg)
75+
is_stanfile <- has_file && (noedit_msg %in% readLines(dest_file, n = 5))
7676
if (has_file && !is_stanfile) {
7777
# non-stan file found: don't overwrite
7878
if (warn) .warning_nowrite(file.path(basename(pkgdir), ...))
@@ -81,7 +81,13 @@
8181
if (!has_file || is_stanfile) {
8282
if (noedit && (file_lines[1] != noedit_msg)) {
8383
# add "noedit" to top of file
84-
file_lines <- c(noedit_msg, "", file_lines)
84+
if (startsWith(file_lines[1], "#!")) {
85+
# in this case noedit_msg goes on 2nd line so file starts with #! interpreter line
86+
# see https://github.com/stan-dev/rstantools/issues/82
87+
file_lines <- c(file_lines[1], "", noedit_msg, "", file_lines[-1])
88+
} else {
89+
file_lines <- c(noedit_msg, "", file_lines)
90+
}
8591
}
8692
if (is_stanfile) {
8793
# stan file found: check if it needs to be overwritten

R/use_rstan.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ use_rstan <- function(pkgdir = ".", license = TRUE, auto_config = TRUE) {
228228
noedit_msg <- .rstantools_noedit(conf_name)
229229
conf_name <- file.path(pkgdir, conf_name)
230230
if (file.exists(conf_name) &&
231-
(readLines(conf_name, n = 1) == noedit_msg)) {
231+
(noedit_msg %in% readLines(conf_name, n = 5))) {
232232
file.remove(conf_name) # Stan file found. remove it
233233
} else FALSE # no stan file found
234234
})

0 commit comments

Comments
 (0)