0
xfun <- function(yvar, newvar){
  df %>% 
    pull(yvar) %>% 
    lmoms(., nmom=4) %>%    # Estimates some parameters
    {. ->> newvar}            # Stores list
}


xfun("var2", "newvar2")

But this doesn't work. I get new output.

But this works:

xfun <- function(yvar){
  df %>% 
    pull(yvar) %>% 
    lmoms(., nmom=4) %>%    # Estimates some parameters
    {. ->> "newvar2"}            # Stores list
}


xfun("var2")

So, how can I pass the newvar as a function argument to store this intermediate output?

Open to a different way of accomplishing this as well.

maximusdooku
  • 5,242
  • 10
  • 54
  • 94
  • 2
    It's not entirely clear to me why you'd go through all these sorts of contortions rather than just assigned the result of `xfun` to a (named) object, i.e. `obj <- xfun()`, and then just use things like named lists if you need flexible naming. – joran Oct 11 '18 at 19:25
  • I don't understand what you want this function to do. It helps to provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with input and desired output so that possible solutions can be tested. If this worked, what would be the result? – MrFlick Oct 11 '18 at 19:25
  • Right. I think I will just go that route. I was overthinking it. – maximusdooku Oct 11 '18 at 19:42

0 Answers0