[R] Overriding predict based on newdata...

Jonathan Greenberg jgrn at illinois.edu
Sun Mar 16 22:09:57 CET 2014


R-helpers:

I'm having some trouble with this one -- I figure because I'm a bit of
a noob with S3 classes...  Here's my challenge: I want to write a
custom predict statement that is triggered based on the presence and
class of a *newdata* parameter (not the "object" parameter).  The
reason is I am trying to write a custom function based on an oddly
formatted dataset that has been assigned an R class.  If the predict
function "detects" it (class(newdata) == "myweirdformat") it does a
conversion of the newdata to what most predict statements expect (e.g.
a dataframe) and then passes the converted dataset along to the
generic predict statement.  If newdata is missing or is not of the odd
class it should just pass everything along to the generic predict as
usual.

What would be the best way to approach this problem?  Since (my
understanding) is that predict is dispatched based on the object
parameter, this is causing me confusion -- my object should still
remain the model, I'm just allowing a new data type to be fed into the
predict model(s).

Cheers!

--j

-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
259 Computing Applications Building, MC-150
605 East Springfield Avenue
Champaign, IL  61820-6371
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007



More information about the R-help mailing list