我已经在我的 Windows 机器上尝试了 tidy_source() 并且它工作得很好。但是,当我尝试在 Ubuntu 机器上运行 tidy_source() 时它失败了。
> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.2 LTS
locale:
[1] LC_CTYPE=en_SG.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_SG.UTF-8 LC_COLLATE=en_SG.UTF-8
[5] LC_MONETARY=en_SG.UTF-8 LC_MESSAGES=en_SG.UTF-8
[7] LC_PAPER=en_SG.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_SG.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] formatR_1.2
loaded via a namespace (and not attached):
[1] tools_3.2.1 grid_3.2.1 stats4_3.2.1
将要格式化的示例文本复制到剪贴板,然后我运行tidy_source()
. 出现错误消息,其中箭头指向无效字符(未在 R 中显示):
> tidy_source()
Error in parse(text = x, keep.source = TRUE) :
<text>:1:1: unexpected input
1:
^
相同的过程适用于 Windows 机器上的 R,以及(显然)在formatR 包中提供的示例中的 linux 机器上。
以下示例代码可以正常工作:
## a messy R script
messy = system.file("format", "messy.R", package = "formatR")
tidy_source(messy)
我在这里做错了吗?还是我错过了一些重要的东西?
编辑:根据评论建议,我在调用函数时尝试了以下变体,但它们似乎都不起作用。
> tidy_source(source = "X11_clipboard")
Error in file(con, "r") :
X11 clipboard selection is not supported on this system
> tidy_source(source = "X11_primary")
Error in parse(text = x, keep.source = TRUE) :
<text>:1:1: unexpected input
1:
^
> tidy_source(source = "X11_secondary")
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") : clipboard cannot be opened or contains no text