我正在RStudio中编写以下函数。当我能够成功获得源代码时,该函数将按预期工作。但是,它有时无法提供资源。如下所述,它无法来源。但是,如果我从第四个注释块的末尾删除-
中的一个,则突然将# extract elements to faut.laut.df ----
更改为# extract elements to faut.laut.df ---
,代码源就没有任何问题。有趣的是,删除第四个-
也会从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
+ }
+
影响代码功能的注释行对我来说似乎很奇怪。任何建议,将不胜感激。
答案 0 :(得分:0)
rows = []
for idx in self.your_table.selectionModel().selectedIndexes():
rows.append(idx.row())
rows = list(set(rows))
我已经在最新的稳定RStudio下载中对其进行了检查。也许尝试开发版本,否则我建议使用上面给出的示例代码在https://github.com/rstudio/rstudio/issues上发布一个问题。
这称为代码折叠,我想这是一个功能,而不是错误:https://support.rstudio.com/hc/en-us/articles/200484568-Code-Folding-and-Sections