It might be useful to provide some context on why you are hoping to assign variable names within a function environment, because there might be another strategy to employ.
If you are mainly trying to avoid the standard assignment structure, there is an alternative that doesn't require having dependent objects in different environments.
Instead of
accname <- newacc(accname)
you can use assign() like so:
assign("accname", newacc(accname))
EDIT:
I might be reading this wrong, but I want to make sure that you know that it doesn't really matter what the name of the variable is inside of the function. If you want to re-use the same function, but have the output variable names have different names, then that is something you do when you call the function.
Try running the following code in a new R session, and let me know if this is the type of functionality you're looking for. Notice how the matrix you're returning is called acc
within the function, but when you actually call the function the new variable is just whatever you told the function to return to.
newacc <- function(x){
acc <- matrix(data=x, nrow=1, ncol=2)
colnames(acc) <- c("DEBIT", "CREDIT")
return(acc)
}
accname <- newacc(0)
accname2 <- newacc(10)
accname3 <- newacc(20)