[R] Try Giving Invalid Argument Type Error

David Winsemius dwinsemius at comcast.net
Sat May 19 23:17:24 CEST 2012


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

> 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

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

See last example in ?try

-- 
David
>
>
> Any help would be most appreciated.
>
> --John Sparks
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list