Plot Rscript无法从命令行打印xts
我有一个Plot Rscript无法从命令行打印xts,plot,command-line-interface,xts,zoo,Plot,Command Line Interface,Xts,Zoo,我有一个Rscript为我做了一些工作,其中之一就是绘制股票价格数据(可以是每日、每小时或滴答数据)。我能够从终端发出命令来绘制matrix,但是绘制xts就是不起作用 下面我使用docopt包来实现一个过于简化的R命令行界面,该界面足以演示所描述的问题。我相信这个问题更多的是plot和xts 更改命令行界面实现应该是安全的(但您必须保持测试功能完好无损) 当我从CLI运行test.matrix()时,打开了一个png文件,显示了我期望的绘图。 当我从CLI运行test.xts()时,弹出一个错
Rscript
为我做了一些工作,其中之一就是绘制股票价格数据(可以是每日、每小时或滴答数据)。我能够从终端发出命令来绘制matrix
,但是绘制xts
就是不起作用
下面我使用docopt
包来实现一个过于简化的R
命令行界面,该界面足以演示所描述的问题。我相信这个问题更多的是plot
和xts
更改命令行界面实现应该是安全的(但您必须保持测试功能完好无损)
当我从CLI运行test.matrix()
时,打开了一个png文件,显示了我期望的绘图。
当我从CLI运行test.xts()
时,弹出一个错误,说没有名为“test2.png”的文件;对于xts
对象,该文件甚至不存在
首先
为什么打印xts
在这种情况下不起作用?是否有从CLI打印xts
的解决方法
我正在运行基于Debian 10的Linux系统
# code in test.R
library(dplyr)
library(xts)
test.matrix <- function(){
data(sample_matrix)
png("test.png")
plot(x = sample_matrix,
main = paste("Test", "xts", sep=" "))
dev.off()
browseURL("test.png")
}
test.xts <- function(){
data(sample_matrix)
png("test2.png")
sample.df <- sample_matrix %>% as.data.frame()
test.data <- sample.df$Open
test.date <- as.Date(rownames(sample.df))
test <- xts(test.data, order.by=test.date)
plot(x = test,
main = paste("Test", "xts", sep=" "))
dev.off()
browseURL("test2.png")
}
# code in Rscript rf.R
# rf.R test
#!/usr/bin/Rscript --vanilla
# for demo purpose, the actual paths to r files are omitted.
# They are just the usual absolute paths to files under project directory.
suppressMessages(source('test.R'))
readr::read_file('rf_doc') -> doc
args <- docopt(doc, "test", version="1.0\n")
if (args$test){
test.xts()
#test.matrix()
}
# rf_doc, a plain txt file (in Linux it has no file extension).
# the file dictates how the rf command is going to work.
# the pattern is used by `docopt` package.
Usage:
rf test
rf --help
Options:
--help show this help page.
#test.R中的代码
图书馆(dplyr)
图书馆(xts)
测试矩阵