How can I write into a function a way to detect if the output is being assigned (<-
) to something? The reasoning is I'd like to print a message if it is not being assigned and just goes to the console but if it is being assigned I'd like it not to print the message.
Here's a dummy example and how I'd like it to behave:
fun <- function(x) {
if (being_assigned) {
print("message")
}
return(x)
}
#no assignment so message prints
> fun(6)
[1] "message"
[1] 6
#assignment so message does not prints
> x <- fun(6)
The being_assigned
in the function is the imaginary unknown condition I'd like to detect but don't know how.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…