quantmod icon indicating copy to clipboard operation
quantmod copied to clipboard

proposed symbol list utility function

Open ethanbsmith opened this issue 4 years ago • 1 comments
trafficstars

Description

symbol cleanup utility function i use. i can turn this into a pr if you think its worth moving into quantmod

cleanSymbolList <- function(Symbols, to.upper = F, filter.na = T) {
  importDefaults("cleanSymbolList")
  if (is.null(Symbols)) return(NULL)
  if (length(Symbols) == 0) return(character())
  
  if (is.list(Symbols)) Symbols <- unlist(Symbols)
  if (!is.character(Symbols)) stop( "cleanSymbolList only accepts chracter input")
  
  Symbols <- unique(trimws(unlist(strsplit(Symbols, ";"))))
  
  if (to.upper) Symbols <- toupper(Symbols)
  if (filter.na) Symbols <- Symbols[!is.na(Symbols)]
  return(Symbols)
}

ethanbsmith avatar Dec 04 '20 13:12 ethanbsmith

Thanks for the proposal. Can you explain the purpose of the function, to make sure I understand what it's doing? That will help me decide whether it's worth moving into quantmod.

A couple thoughts:

  1. I would change filter.na to na.rm to be consistent with other R functions.
  2. I would set Symbols = NULL in the argument list. Otherwise I'm not sure the is.null(Symbols) will work if Symbols is missing.

joshuaulrich avatar Dec 12 '20 17:12 joshuaulrich