2015-09-06 47 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電子表格的單個路徑,但是您已經傳遞了具有多個路徑的字符向量。