I stumbled uppon one problem:
temp.fun <- function() {}
as.character(temp.fun)
yields an error. I undersand, why it is not possible to "convert" a function into a character.
Question is, what properties to add to a function so that the method as.character
returns a string defined by myself?
Thanks a lot!
deparse
can help:
> deparse( temp.fun )
[1] "function () " "{" "}"
Going further with the details of your comment, what you can do is create a class that derives function
and pass this instead of the function.
setClass( "myFunction", contains = "function" )
setMethod( "as.character", "myFunction", function(x, ...){
deparse( unclass( x ) )
} )
So that when you pass a function to the third party package, you pass a myFunction
instead:
f <- new( "myFunction", function(){} )
as.character(f)
# [1] "function () " "{" "}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With