I've imported package called "stabledist". It includes function "rstable"
When I do this
my_fun <- function(function_from_library)
{
function_from_library <- match.fun(function_from_library)
print(some_data <- function_from_library)
}
my_fun (5, rstable(5, alpha = 1.7, beta = 0, gamma = 1.0, delta = 1.0))
I get error:" Error in match.fun(some_distr) : 'rstable(5, alpha = 1.7, beta = 0, gamma = 1, delta = 1)' is not a function, character or symbol "
Everything works fine, whrn match.fun is deleted. Is there anyway to import library that it can be visible to others? Or I can just skip match.fun?
This is how I implemented my suggestion:
library(stabledist )
my_fun <- function(function_from_library, ...)
{
function_from_library <- match.fun(function_from_library)
print(some_data <- function_from_library(...))
}
my_fun ( rstable, 5, alpha = 1.7, beta = 0, gamma = 1.0, delta = 1.0)
#[1] 1.4600308688 -0.0004999279 1.9301805374 -1.3276383194 0.9137183709
It does require also knowing how to use the ellipsis-mechanism for passing lists of arbitrary length to functions as Roland had additionally commented. The print mechanism will not actually create a data-vector of values. To do that you would need to assign ("<-") the result "outside" the function body (and so the print() call is not needed either).
library(stabledist )
my_fun <- function(function_from_library, ...)
{
function_from_library <- match.fun(function_from_library)
function_from_library(...) }
some_data <- my_fun ( rstable, 5, alpha = 1.7, beta = 0, gamma = 1.0, delta = 1.0)
some_data
# 5 random values are printed at console.
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