【发布时间】:2019-12-23 11:28:37
【问题描述】:
我正在尝试通过页面在 R 中打印一个简单的输出,目前在 Windows 10 机器上。它过去有效,现在不再有效。 Windows 通常会询问应使用哪个程序打开文件,但不再弹出。还有其他人遇到这些问题,或者知道如何解决吗?可能与最新的大型 Windows 更新有关,但不一定是。我正在使用 Rstudio 作为 IDE。
示例:
x <- data.frame(matrix(1:9,3,3))
page(x,method="print") # no effect
Windows 10(家庭版),版本:10.0.18362 Build 18362。同时,将 RStudio 更新到最新版本 1.2.1335(64 位),R 也更新到最新版本 3.6.1(64 位)。问题仍然存在。
编辑:使用 Windows 7 机器测试,Rstudio 最新版本 1.2.1335(64 位)。在这里工作正常。问题似乎与 Windows 10 有关。
Edit2:使用不同的 Windows 10(企业版)机器进行测试,版本:10.0.14393 Build 14393。在这里它工作正常。问题似乎与最新版本的 Windows 10 和/或家庭版与企业版有关。
有人提到实现是系统相关的。这是 Windows 实现:
page <-
function (x, method = c("dput", "print"), ...)
{
local.file.show <- function(file, title = subx, delete.file = TRUE,
pager = getOption("pager"), ...) file.show(file,
title = title, delete.file = delete.file, pager = pager)
local.dput <- function(x, file, title, delete.file, pager,
...) dput(x, file, ...)
local.print <- function(x, title, delete.file, pager, ...) print(x,
...)
if (is.character(x) && length(x) == 1L) {
subx <- x
parent <- parent.frame()
if (exists(subx, envir = parent))
x <- get(subx, envir = parent)
else stop(gettextf("no object named '%s' to show",
x), domain = NA)
}
else {
subx <- deparse(substitute(x))
}
file <- tempfile("Rpage.")
if (match.arg(method) == "dput")
local.dput(x, file, ...)
else {
sink(file)
local.print(x, ...)
sink()
}
local.file.show(file, ...)
}
尝试通过逐行执行上面的代码来跟踪错误,我发现文件在Local/Temp文件夹中正确创建,但是函数的剩余代码没有返回结果(测试了所有不同的方式)。更具体地说,file.show("C:\\Users\\XYZ\\AppData\\Local\\Temp\\RtmpOmW06C\\Rpage.1d0562862a6") 只是没有效果。命令file.show 适用于其他路径。另外我刚刚发现,一旦我手动打开文件,之后我也可以在 RStudio 中成功使用该命令。所以不是授权错误;相反,如果文件类型未知,Windows 不再询问是否应该打开文件。如果有人可以确认会很好。
任何提示都非常受欢迎。
【问题讨论】:
-
这与 RGui、RStudio、Rscript 等有关吗? (我在 R/RStudio/Ubuntu 19.04 上,它按预期工作。)
-
@RuiBarradas 感谢您的提问,这是与 RStudio 相关的
-
page调用file.show并根据后一个函数的帮助页面“寻呼机的实现方式高度依赖于系统。” -
@RuiBarradas 谢谢,但这应该适用于 Win 10,不是吗?那里有很多 Win 用户,而且它在过去有效。我只是想知道问题是由 Windows 还是由 RStudio 引起的。任何提示可以做什么?
-
我可以确认它适用于我的 Win10。你能试试
page(x,method="dput")我在RStudio 1.0.143上。