Skip to content

Try Giving Invalid Argument Type Error

2 messages · Sparks, John, David Winsemius

#
Dear R Helpers,

I am getting an error message from the try function that I don't
understand so I am hoping that someone can help.

I am scraping from web pages, but sometimes they disappear.  When that
happens I need to control for it with some sort of function.

This web page is parsed without a problem.


exh<-"NASDAQ"
tic<-"EGHT"
URL<-paste("http://www.advfn.com/p.php?pid=financials&btn=istart_date&mode=quarterly_reports&symbol=",
exh,"%3A",tic,"&istart_date=0", sep = "")
doc <- htmlParse(URL)

However, when I change the value of tic it will not.

tic<-"AACOU"
URL<-paste("http://www.advfn.com/p.php?pid=financials&btn=istart_date&mode=quarterly_reports&symbol=",
exh,"%3A",tic,"&istart_date=0", sep = "")
doc <- htmlParse(URL)
Error in htmlParse(URL) :
  error in creating parser for
http://www.advfn.com/p.php?pid=financials&btn=istart_date&mode=quarterly_reports&symbol=NASDAQ0X1.CP-1072AACOU&istart_date=0

I tried to account for this using the try function but I get the error
below that I don't understand.


options(error = expression(NULL))
URL<-paste("http://www.advfn.com/p.php?pid=financials&btn=istart_date&mode=quarterly_reports&symbol=",
exh,"%3A",tic,"&istart_date=0", sep = "")
if(
!is(
try(
doc <- htmlParse(URL)
,"try-error")
)
)

{
qtrstop <- xpathApply(doc, "count(//select/option)")-5
}
Error in !silent : invalid argument type


Any help would be most appreciated.

--John Sparks
#
On May 19, 2012, at 5:00 PM, Sparks, John James wrote:

            
Generally one needs to test for inherits(try(...), "try-error")

See last example in ?try