The Fun of Error Trapping: R Package Edition

February 25, 2013
By

(This article was first published on randyzwitch.com » R, and kindly contributed to R-bloggers)

For the last month or so I’ve been working on an R package to make accessing the Adobe (Omniture) Digital Marketing Suite Reporting API easier.  As part of this development effort, I’m at the point where I’m intentionally introducing errors into my function inputs, trying to guess some of the ways useRs might incorrectly input arguments into each function.  Imagine my surprise when I saw this:

> result <- content(json)
Loading required package: XML
Error in parser(content, …) : could not find function “htmlTreeParse”
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
there is no package called ‘XML’

The main idea behind the functions I’ve written is making REST calls to the Omniture API, which done correctly return valid JSON. From there, each JSON string is converted from binary or whatever formatting they come back as using the content function from the httr package. Without specifying any arguments to the content function, the function tries to guess at the proper translation method.

The guessing is all fine and good until you don’t pass a valid JSON string!  In this case, the error message is guessing that it might be XML (the returned error is actually HTML), tries to load the XML package…then says it can’t load the XML package. A two-for-one error!

Maybe it’s just me, but I’m finding this hilarious after a long day of programming. Maybe it’s because I’m not longer intimidated by an error like this, and as such, I’ve gotten over the steep learning curve of R.

Note:  Hadley, if you read this, I’m not saying your httr package has any sort of bug or anything. Just that I found this particular error amusing.

The Fun of Error Trapping: R Package Edition is an article from randyzwitch.com, a blog dedicated to helping newcomers to Web Analytics, with a heavy focus on Wordpress self-hosted blogs and Google Analytics. If you liked this post, please visit randyzwitch.com to read more. Or better yet, tell a friend...the best compliment is to share with others!

To leave a comment for the author, please follow the link and comment on his blog: randyzwitch.com » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.