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

getSymbols.yahooj infinite loop if symbol has no data #63

Closed
joshuaulrich opened this issue Jul 26, 2015 · 1 comment
Closed

getSymbols.yahooj infinite loop if symbol has no data #63

joshuaulrich opened this issue Jul 26, 2015 · 1 comment
Labels

Comments

@joshuaulrich
Copy link
Owner

There's a potential for an infinite loop if getSymbols.yahooj is called on a symbol that has no data. For example, getSymbols("foo", src="yahooj"). The patch below seems to fix the issue.

diff --git a/R/getSymbols.R b/R/getSymbols.R
index 304dc80..a4dc742 100644
--- a/R/getSymbols.R
+++ b/R/getSymbols.R
@@ -388,13 +388,18 @@ function(Symbols,env,return.class='xts',index.class="Date",

                 fdoc <- XML::htmlParse(tmp)
                 rows <- XML::xpathApply(fdoc, "//table[@class='boardFin yjSt marB6']//tr")
-                if (length(rows) == 1) break
+                if (length(rows) <= 1) break

                 totalrows <- c(totalrows, rows)
                 page <- page + 1
             }
             if(verbose) cat("done.\n")
-            
+
+            if (is.null(rows)) {
+              warning("No historical data for ", Symbols[[i]], ", skipping...")
+              next
+            }
+
             # Available columns
             cols <- c('Open','High','Low','Close','Volume','Adjusted')

@wthielen what do you think?

@wthielen
Copy link
Contributor

Looks good to me, @joshuaulrich. Checked the source for such a page, and indeed there is no table matching that xpath.
I think we need a better method to check for historical data, but then I'd need a company that is going IPO and is registered, but does not have any historical data, to see what totalrows looks like then.

joshuaulrich added a commit that referenced this issue Apr 18, 2018
The while() loop never terminates if there is no table matching the
xpath used to create 'rows'. Break if there is less than one row, and
then throw an error.

Fixes #63.
@joshuaulrich joshuaulrich added this to the Release 0.4-14 milestone Nov 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants