I have a function in string format "dnorm(0,1)"
which I want to evaluate but I need to make a change to string first. How do I subsequently run the function from character format?
function_char_format = str_replace("dnorm(0,1),.,"r") %>%
str_replace(".","r") %>%
str_replace("\\(","(1e4, ") #this returns "rnorm(100,0,1)"
execute_function??(function_char_format)
context: (I'm making a function where I'm extracting a distribution like "dnorm" from an r-object and need the corresponding "rnorm()" . The solution should also be applicable for "dbinom", "dpois" etc.)
Edit: added str_replace line