quantmod
quantmod copied to clipboard
proposed symbol list utility function
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)
}
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:
- I would change
filter.natona.rmto be consistent with other R functions. - I would set
Symbols = NULLin the argument list. Otherwise I'm not sure theis.null(Symbols)will work ifSymbolsis missing.