r语言 - 影响 RStudio 中函数源代码的注释行



我正在RStudio中编写以下函数。当我能够成功获取它时,该函数按预期工作。但是,它有时无法获取。如下文所述,它无法来源。但是,如果我从第四个注释块的末尾删除其中一个-# extract elements to faut.laut.df ----更改为突然# extract elements to faut.laut.df ---代码源而没有任何问题。有趣的是,删除第 4-也会从 RStudio 文档大纲中删除extract elements to faut.laut.df

######################################## # # # # # # # # # #
# create auth_search ---------------------------------------
# create function that wil search for
# all last authors who have published
# on the search terms
######################################## # # # # # # # # # #
auth_search <- function(
term_set,
elmnt = NULL,
download = T,
max_records = 1e6
) {
######################################## # # # # # # # # # #
# search -> search.l --------------------------------------
# search pubmed using web history
# and write out results
######################################## # # # # # # # # # #
require(rentrez)
require(dplyr)
# require(data.table)
# require(rlist)
# require(XML)
search.l <- entrez_search(
db = "pubmed",
term = term_set,
use_history = T
)
saveRDS(search.l, paste0(search_name, "_search.l.RDS"))
######################################## # # # # # # # # # #
# summarize -> summary.l -----------------------------------
# get summaries of search hits using
# web history and write out results
######################################## # # # # # # # # # #
if (download) {
if (search.l$count > max_records) {
paste0(
"greater than ",
max_records,
" laut records found for this name"
)
}
else if (search.l$count != 0) {
for (seq_start in seq(1, search.l$count, download_max)) {
if (seq_start == 1) {
i <- 1
cat(paste0(
"cycle ", i, " of ",
ceiling(search.l$count / download_max), "n"
))
summary.l <- entrez_summary(
db = "pubmed",
web_history = search.l$web_history,
always_return_list = T,
retmax = download_max,
retstart = seq_start
)
}
else {
i <- i + 1
cat(paste0(
"cycle ", i, " of ",
ceiling(search.l$count / download_max), "n"
))
summary.l <- append(
summary.l,
entrez_summary(
db = "pubmed",
web_history = search.l$web_history,
always_return_list = T,
retmax = download_max,
retstart = seq_start
)
)
}
}
class(summary.l) <- c("esummary_list", "list")
rm(seq_start, i)
saveRDS(summary.l, paste0(search_name, "_summary.rds"))
######################################## #
# extract elements to faut.laut.df ----
# extract desired information from
# esummary, convert to dataframe
######################################## #
faut.laut.l <- extract_from_esummary(
esummaries = summary.l,
elements = elmnt,
simplify = F
)
faut.laut.df <- rbindlist(faut.laut.l)
faut.laut.df
}
else {
out <- "no last author publications"
out
}
}
else {
search.l
}
}

这是编译失败时控制台显示的内容:

> ######################################## # # # # # # # # # #
> # create auth_search ---------------------------------------
> # create function that wil search for
> # all last authors who have published
> # on the search terms
> ######################################## # # # # # # # # # #
> auth_search <- function(
+     term_set,
+     elmnt = NULL,
+     download = T,
+     max_records = 1e6
+ ) {
+     ######################################## # # # # # # # # # #
+     # search -> search.l --------------------------------------
+     # search pubmed using web history
+     # and write out results
+     ######################################## # # # # # # # # # #
+     require(rentrez)
+     require(dplyr)
+     # require(data.table)
+     # require(rlist)
+     # require(XML)
+     search.l <- entrez_search(
+       db = "pubmed",
+       term = term_set,
+       use_history = T
+     )
+     saveRDS(search.l, paste0(search_name, "_search.l.RDS"))
+     ######################################## # # # # # # # # # #
+     # summarize -> summary.l -----------------------------------
+     # get summaries of search hits using
+     # web history and write out results
+     ######################################## # # # # # # # # # #
+     if (download) {
+         if (search.l$count > max_records) {
+             paste0(
+                 "greater than ",
+                 max_records,
+                 " laut records found for this name"
+             )
+         }
+         else if (search.l$count != 0) {
+             for (seq_start in seq(1, search.l$count, download_max)) {
+                 if (seq_start == 1) {
+                     i <- 1
+                     cat(paste0(
+                         "cycle ", i, " of ",
+                         ceiling(search.l$count / download_max), "n"
+                     ))
+                     summary.l <- entrez_summary(
+                         db = "pubmed",
+                         web_history = search.l$web_history,
+                         always_return_list = T,
+                         retmax = download_max,
+                         retstart = seq_start
+                     )
+                 }
+                 else {
+                     i <- i + 1
+                     cat(paste0(
+                         "cycle ", i, " of ",
+                         ceiling(search.l$count / download_max), "n"
+                     ))
+                     summary.l <- append(
+                         summary.l,
+                         entrez_summary(
+                             db = "pubmed",
+                             web_history = search.l$web_history,
+                             always_return_list = T,
+                             retmax = download_max,
+                             retstart = seq_start
+                         )
+                     )
+                 }
+             }
+             class(summary.l) <- c("esummary_list", "list")
+             rm(seq_start, i)
+             saveRDS(summary.l, paste0(search_name, "_summary.rds"))
+             ######################################## #
+             # extract elements to faut.laut.df ----
+             # extract desired information from
+             # esummary, convert to dataframe
+             ######################################## #
+             faut.laut.l <- extract_from_esummary(
+                 esummaries = summary.l,
+                 elements = elmnt,
+                 simplify = F
+             )
+             faut.laut.df <- rbindlist(faut.laut.l)
+             faut.laut.df
+         }
+

影响代码功能的注释行对我来说似乎很奇怪。任何建议将不胜感激。

最小问题示例

# if you copy/paste this into RStudio, there's an arrow on the margin to
# compact the ---- as if it's in brackets like {}
f <- function() {
# extract elements to faut.laut.df -----
}

我已经在最新的稳定 RStudio 下载中检查了它。也许尝试开发版本,否则我建议使用我上面给出的示例代码在 https://github.com/rstudio/rstudio/issues 上打开一个问题。

更新:

它被称为代码折叠,我想这是一个功能而不是一个错误:https://support.rstudio.com/hc/en-us/articles/200484568-Code-Folding-and-Sections

最新更新