joshuaulrich / quantmod

Quantitative Financial Modelling Framework
http://www.quantmod.com/
GNU General Public License v3.0
798 stars 219 forks source link

proposed symbol list utility function #320

Open ethanbsmith opened 3 years ago

ethanbsmith commented 3 years ago

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)
}
joshuaulrich commented 3 years ago

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.