R do.call函数中的错误[关闭]
Posted
技术标签:
【中文标题】R do.call函数中的错误[关闭]【英文标题】:Error in R do.call function [closed] 【发布时间】:2015-09-06 04:22:29 【问题描述】:当我逐行运行以下代码时,一切都很好,除非光标转到 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))
请帮助解决此问题。
【问题讨论】:
转储大量代码并询问问题出在哪里被认为是不好的形式。尝试提供一个最小的可重现示例;请参阅如何提问***.com/help/how-to-ask。通过简化这个问题来练习。 【参考方案1】:问题是read_excel
采用单个路径指向 Excel 电子表格,但您传递的字符向量具有多个路径。
【讨论】:
以上是关于R do.call函数中的错误[关闭]的主要内容,如果未能解决你的问题,请参考以下文章
R中的TukeyHSD函数不完全错误,不知道如何解决[已关闭]。