My thanks to:
Rolf Turner
Sam Buttrey
Bill Dunlap (Insightful Corp)
Dan Rie
Mark Durst
for their quick responses and for setting me straight!
All pointed out that I need to use the where argument to assign the object to
a dataframe.
Rolf also pointed out that I could clean up my code and get rid of the
concatenation.
He also suggested that it was better practice to return the object from the
function than to create the object inside the function.
I now understand that I could write the code this way:
myfunc<-function(theData)
{
y<-paste(deparse(substitute(theData)),".spp",sep="")
assign(y,spp(theData),where=1,immediate=T)
}
but that it would better to write:
myfunc<-function(theData)
{
return(spp(theData))
}
and call this from elsewhere (e.g. the command line) with:
my_object_name<-myfunc(name_of_data)
I have tried both methods and they work just fine.
Thanks to Mark for some code he sent as well which was helpful.
Greatly appreciated
Cheers,
Alastair
Alastair Dempster
|