[R] Function returning multiple objects but printing only one

Daniel Caro dcarov at gmail.com
Mon Jul 13 23:06:43 CEST 2015


Hello,

Sorry if this has already been addressed before but I could not find any
helpful references.

I would like to create a function that outputs a single element of a list
but stores all elements, similar to  'lm' and many other functions. There
are several answers on how to return multiple objects with lists, for
example:

http://r.789695.n4.nabble.com/How-to-return-multiple-values-in-a-function-td858528.html

http://stackoverflow.com/questions/8936099/returning-multiple-objects-in-an-r-function

But the examples show how to print multiple outputs, such as

functionReturningTwoValues <- function() {return(list(first=1, second=2))}
functionReturningTwoValues()

And I only want the function to print a single element from the list but
still store the other elements such that they can be retrieved with
functionReturningTwoValues$first, for example. My function produces
bootstrap coefficients so clearly I don't want to print the bootstrap
output but I do want users to be able to access it.

Many thanks,
Daniel

	[[alternative HTML version deleted]]



More information about the R-help mailing list