Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access odd-named object returned by getSymbols

Tags:

r

quantmod

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?

like image 300
Chris Jackson Avatar asked Feb 18 '23 14:02

Chris Jackson


2 Answers

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))
like image 192
Joshua Ulrich Avatar answered Mar 05 '23 19:03

Joshua Ulrich


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

like image 45
hd1 Avatar answered Mar 05 '23 20:03

hd1