当我按下运行以下代码行时,一切都很好,除非当cusrsor转到do.call时。
require(highfrequency)
require(quantmod)
require(readxl)
require(xlsx)
setwd("file_path")
input_files=list(list.files(path="file_path", recursive=T, pattern='.xlsx'))
processLIQ <- function(input_files)
{
#reading bid data and making df object of it
bid_df<-read_excel(input_files, sheet = 1, col_names = TRUE, col_types = NULL, na = "", skip = 0)
#bid_df$TIMESTAMP<-as.POSIXct(bid_df$TIMESTAMP, format="%H:%M:%S")
#reading ask data and making df object of it
ask_df<-read_excel(input_files, sheet = 2, col_names = TRUE, col_types = NULL, na = "", skip = 0)
#merging df objects of bid and ask directly and making xts object of qdata
qdata_df <- merge(ask_df, bid_df, by = "TIMESTAMP")
str(qdata_df)
qdata_xts_raw<-xts(qdata_df[,-1], order.by=qdata_df[,1])
str(qdata_xts_raw)
#Merge multiple quote entries with multiple timestamp
qdata_xts_m<-mergeQuotesSameTimestamp(qdata_xts_raw, selection = "median")
str(qdata_xts_m)
#reading trade data and making xts object of it
trade_df<-read_excel(input_files, sheet = 3, col_names = TRUE, col_types = NULL, na = "", skip = 0)
str(trade_df)
trade_xts_raw <- xts(trade_df[,-1], order.by=trade_df[,1])
#Merge multiple trade entries with multiple timestamp
trade_xts_m<-mergeTradesSameTimestamp(trade_xts_raw, selection = "median")
str(trade_xts_m)
#Matching Trade and Quotes
tqdata=matchTradesQuotes(trade_xts_m,qdata_xts_m)
#liquidity computation
#Quoted Spread(1)
quoted_spread<-tqLiquidity(tqdata,trade_xts_m,qdata_xts_m,type="qs")
qs_30<-aggregatets(quoted_spread,FUN="mean",on="minutes",k=30)
indexTZ(qs_30) <- "UTC"
Canara_out_xts<-merge(qs_30,pqs_30,log_qs_30,es_30,depth_xts_30,Rupee_depth_xts_30,log_returns_30,volume_30)
indexTZ(Canara_out_xts) <- "UTC"
write.xlsx(Canara_out_xts, file = file.path("output_file_path", paste0("CAN_test6", i,".xlsx")))
}
do.call(processLIQ, input_files)
错误是
Error in switch(ext, xls = "xls", xlsx = "xlsx", xlsm = "xlsx", stop("Unknown format .", :
EXPR must be a length 1 vector
In addition: Warning message:
In if (!file.exists(path)) { :
the condition has length > 1 and only the first element will be used
在控制台中浏览与源查看器一起打开,其中包含代码:
function (path, sheet = 1, col_names = TRUE, col_types = NULL,
na = "", skip = 0)
{
path <- check_file(path)
ext <- tolower(tools::file_ext(path))
switch(excel_format(path), xls = read_xls(path, sheet, col_names,
col_types, na, skip), xlsx = read_xlsx(path, sheet, col_names,
col_types, na, skip))
}
请帮助解决此问题。
答案 0 :(得分:1)
问题是read_excel
只需一条路径到Excel电子表格,但您已经传递了一个包含多条路径的字符向量。