[R] Change default values of a function

Duncan Murdoch dmurdoch at pair.com
Thu May 13 03:30:10 CEST 2004


On Wed, 12 May 2004 20:13:09 +0100, Jesus Frias <Jesus.Frias at dit.ie>
wrote:

>Dear R-helpers,
>	I would like to change the default value of a functions that is call by a
>package. The function deparse() is called by a set of functions from a
>library and because I don't think is appropriate to change the library, I am
>trying to change the default value in deparse().
>
>	At the moment the only solution I have come across is to place a function
>in my working environment like this,
>
>deparse <- function(expr,width.cutoff=400,backtick=mode(expr) %in%
>c("call","expression","("),...) deparse(expr,width.cutoff=400,backtick,...)
>
>	I only want to change the width.cutoff of the function and I wonder of
>there is any more elegant way to do it.

That looks like an infinite recursion; I assume you meant 

 deparse <- function(expr,width.cutoff=400,backtick=mode(expr) %in%
c("call","expression","("),...) {
	  base::deparse(expr,width.cutoff=400,backtick,...)
 }

I think this is unlikely to work due to namespaces.  A package with a
namespace will certainly find the base deparse() function rather than
yours. (I forget the search order for packages without namespaces.)

A better strategy is to modify the function that you call yourself,
i.e. the function in the package that calls deparse().  If you don't
call that one directly, you may need to make extensive changes to the
package:  and it might be a good idea to explain to the package author
why width flexibility is useful to you, and then they'll incorporate
the patch you supply into the main distribution of the package.

Duncan Murdoch




More information about the R-help mailing list