Access odd-named object returned by getSymbols

I'm downloading data from Yahoo using quantmod:

> getSymbols("HNZ-A.TO")
[1] "HNZ-A.TO"
Warning message:
In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :
  downloaded length 70893 != reported length 200

The file shows up in my R workspace. The data is there and I can use edit to see the object, but I can't use the object. For example:

> head(HNZ-A.TO)
Error in head(HNZ - A.TO) : object 'HNZ' not found

What can I do to use this object?


Use back-ticks or get.

HNZA.TO <- `HNZ-A.TO`
HNZA.TO <- get("HNZ-A.TO")

Or you could avoid this all-together by setting auto.assign=FALSE in your call to getSymbols.

HNZA.TO <- getSymbols("HNZ-A.TO", auto.assign=FALSE)

You might also want to adjust the column names, via:

colnames(HNZA.TO) <- make.names(colnames(HNZA.TO))

HNZ <- getSymbols('HNZ-A.TO', auto.assign=FALSE) per the help page for getSymbols.


Another alternative is to setSymbolLookup to tell getSymbols to use a different Symbol in the query.

> setSymbolLookup(HNZ=list(src="yahoo", name="HNZ-A.TO"))
> getSymbols("HNZ")
[1] "HNZ"