2015-09-06 101 views
-1

当我运行下面的代码行时,除了当cusrsor进入do.call时,一切都很好。R 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

转储大量代码并询问问题出在哪里,这被认为是不正确的形式。尝试提供一个最小可重现的例子;请参阅如何提问https://stackoverflow.com/help/how-to-ask。通过简化这个问题来练习。 –

回答

1

问题是,read_excel需要一个Excel电子表格的单个路径,但是您已经传递了具有多个路径的字符向量。