-1

When I run the following code line by by, everything is fine except when the cusrsor goes to 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)

The error is

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

Browse in console is opened along with Source viewer which has the code:

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))
}

Kindly help in resolving this issue.

CoderGuy123
  • 6,219
  • 5
  • 59
  • 89
gaurav kumar
  • 859
  • 2
  • 10
  • 24
  • It's considered bad form to dump a large chunk of code and ask where the problem is. Try to provide a minimal reproducible example; see How To Ask https://stackoverflow.com/help/how-to-ask. Practise by simplifying this question. – Richie Cotton Sep 06 '15 at 05:38

1 Answers1

1

The problem is that read_excel takes a single path to an Excel spreadsheet, but you've passed a character vector with more than one path.

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360