【问题标题】:Is it possible to modify a .js file from r console?是否可以从 r 控制台修改 .js 文件?
【发布时间】:2019-07-30 15:02:36
【问题描述】:

我正在尝试修改工作目录中 .js 文件的内容。我知道我可以使用

在 R 控制台中简单地创建一个空白 .js 文件

file.create("test.js")

但是我怎样才能从 R 控制台里面写呢? R中是否有任何功能可以做到这一点?

我想在 .js 文件中写一些东西,然后我可以使用 system() 函数执行它。

【问题讨论】:

  • 刚刚意识到 cat 是要走的路,我可以简单地将我想在 .js 文件中写入的内容存储在 R 对象中,然后使用 cat(text, file = "test.js" , sep = "\n")。谢谢!

标签: javascript r web-scraping


【解决方案1】:

您可以使用 write 函数写入文件。

https://stat.ethz.ch/R-manual/R-devel/library/base/html/write.html

所以你可以这样做:

file.create("test.js")

code  <- "alert()"

write(code, file="test.js")

正如 joran 在 cmets cat 中指出的那样,也可以。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-06
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 2016-01-18
    • 2012-12-04
    • 2016-08-17
    • 1970-01-01
    相关资源
    最近更新 更多