我最近将R(从4.1.1 High Sierra)和RStudio(2021.09.0 +351)更新到R(4.3.2“Eye Holes”)intel版本和RStudio(2023.09.1 +494)。注意:我确实尝试过支持 Apple Silicon m2 芯片的 ARM 版本,但为了防止出现问题,我又恢复到了 Intel 版本。我正在运行全新的 Mac mini M2 Pro。还安装了最新版本的 XQuartz 2.8.57。我对 R、RStudio 和编码还比较陌生。在我的旧计算机上,我在 RStudio 中运行了一个我经常使用的程序,没有出现任何问题。之后,搬到新计算机后,我遇到了一个我尚未弄清楚的“怪癖”。当我在 RStudio 中运行该程序(它是一个 .Rmd 文件)时,输出按预期工作。它会在 Word 中生成报告。那里没有问题。但是,在执行代码的过程中,控制台应该在使用 message() 函数呈现我的报告的过程中显示一些诊断消息。它不是。不管出于什么原因,它已经消失了。但是,当我仅运行发生此问题的代码块时,它在控制台中显示得很好并且符合预期。我希望能够在报告呈现时查看诊断消息,就像我以前在旧版本的 R 和 Rstudio 中所做的那样。我不再拥有旧电脑了。我觉得这可能是一个设置问题,但无法弄清楚。非常感谢对新手的任何帮助。谢谢。
我在屏幕顶部的“针织”旁边添加了设置的快照。
我还包含了有问题的代码。我尝试将 message=FALSE 更改为 TRUE,warning=TRUE,删除 results='asis" 只是为了看看这是否会做任何事情。它不会。同样,如果我只运行这个块,它本身就可以正常工作。我还应该指出,在运行整个 .Rmd 文件来生成报告时,我根本没有收到任何错误。一切似乎都正常,但我需要在生成报告时在控制台中查看 messages() ,但我没有.
```{r get_types, results='asis', warning=FALSE, message=FALSE}
soil_types <- filtered_database %>%
filter(sample_type == "Soil") %>%
filter(sample_description_number_1 != "OM") %>%
pull(sample_description_number_1) %>%
unique()
# to get them in order and leave room for unanticipated ones
soil_types <- c(intersect(c("GREEN", "TEE", "FAIRWAY", "ROUGH"), soil_types),
sort(setdiff(soil_types, intersect(c("GREEN", "TEE", "FAIRWAY", "ROUGH"), soil_types))))
# for accessibility by other scripts
soil_types <<- soil_types
# check that warm_or_cool has been specified of there are soil samples to analyse
if(is.na(input_params$warm_or_cool) && length(soil_types > 0)) {
stop(paste0("\nIn generate_report(), you specified the warm_or_cool variable as NA.",
"\nIt needs to be either warm or cool in order to analyse the soil samples in the data.
\nPlease check before trying again."))
}
water_types <- filtered_database %>%
filter(sample_type == "Water") %>%
filter(sample_description_number_1 != "OM") %>%
pull(sample_description_number_1) %>%
unique()
water_types <<- water_types
om_types <- filtered_database %>%
filter(sample_description_number_1 == "OM",
sample_type %in% c("Soil", "Physical")) %>%
pull(sample_description_number_2) %>%
unique()
# to get them in order and leave room for unanticipated ones
om_types <- c(intersect(c("GREEN", "TEE", "FAIRWAY", "ROUGH"), om_types),
sort(setdiff(om_types, intersect(c("GREEN", "TEE", "FAIRWAY", "ROUGH"), om_types))))
# for accessibility by other scripts
om_types <<- om_types
if(length(soil_types) == 0) {
message("\nI didn't find any soil types in the database.")
} else {
message(paste0("\nI found the following soil types in the database: ",
paste(unique(soil_types), collapse = ", "),
"."))
}
if(length(water_types) == 0) {
message("I didn't find any water types in the database.")
} else {
message(paste0("I found the following water types in the database: ",
paste(unique(water_types), collapse = ", "),
"."))
}
if(length(om_types) == 0) {
message("I didn't find any OM types in the database.")
} else {
message(paste0("I found the following OM types in the database: ",
paste(unique(om_types), collapse = ", "),
"."))
}
if(testing_report == "No") {
message("\n* Does that seem correct, or do you want to exit to investigate the database before running the rest of the report? *\n")
proceed <- readline("Type c for correct and hit ENTER to proceed, or hit any other key followed by ENTER to exit now. ")
if(proceed != "c") stop("\n\n* Thank you! Please investigate the database before running the report again.* \n\n")
}
```