Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a list when auto.assign = TRUE and there is more than 1 symbol #373

Open
joshuaulrich opened this issue Mar 2, 2023 · 4 comments
Assignees

Comments

@joshuaulrich
Copy link
Owner

getSymbols() currently errors if you specify auto.assign = FALSE with more than one symbol.

Error in getSymbols(c("SPY", "AAPL"), auto.assign = FALSE) : 
  must use auto.assign = TRUE when reloading multiple Symbols

Instead of throwing an error, we can return a named list of xts objects. This will make it easier to avoid the side-effect of assigning to the calling environment without breaking any backward compatibility.

@joshuaulrich joshuaulrich added this to the 0.4.21 milestone Mar 2, 2023
@joshuaulrich joshuaulrich self-assigned this Mar 2, 2023
@ethanbsmith
Copy link
Contributor

this will return different types based on the length of the output (list vs xts)
would be nice to be able to have it always return a list, regardless of length

@joshuaulrich
Copy link
Owner Author

So getSymbols("SPY", auto.assign = FALSE) would return a list? That would break backward compatibility. Maybe leave getSymbols as-is and create an importSymbols() function that always returns a list?

@ethanbsmith
Copy link
Contributor

just thinking out loud:

ideally, getSymbols​ would always return a list and getSymbol​ (singular) would wrap that with an unlist(), and auto.assign and env would get deprecated. if thats an agreed target state, (prolly a big if) whats the best interim approach?

  1. new get_Symbol/get_Symbols that implement new pattern. maybe turn existing getSymbols into a wrapper
  2. overload auto.assign​ to take T,F,"list". very ugly
  3. always return a list for auto.assign​ == FALSE, and implement new getSymbol()​ wrapper. def breaks back-compat, but slightly less ugly
  4. new argument simplify = TRUE, that controls whether to unlist() a single return value, when auto.assign == FALSE​​. doesn't break back-compat, but does add complexity to argument interaction and overall "intuitiveness" of the API

i'd prolly vote for something like 1 or 4

@joshuaulrich
Copy link
Owner Author

Thanks for your thoughts. Making getSymbols() always return a list would break a lot of code, so that's not an option.

I prefer (1) and I like the idea of a get_symbol() function that only works for a single symbol.

@joshuaulrich joshuaulrich removed this from the Release 0.4.21 milestone Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants