gpt4 book ai didi

r - invisible() 返回的对象何时不再不可见?

转载 作者:行者123 更新时间:2023-12-04 10:50:05 26 4
gpt4 key购买 nike

?invisible

Return a (temporarily) invisible copy of an object.



那个括号暗示隐形不会永远持续下去,但我找不到任何可以解释它何时消失的东西。我特别想知道像这样的结构(来自 this old answer of mine ):
printf <- function(...) invisible(print(sprintf(...)))

凡外 invisible可能是不必要的(因为 print 已经将其返回值标记为不可见)。 withVisible()报告说这个函数的返回值是不可见的,但我不知道这是否由语言保证,或者只是它在当前实现中的工作方式。

最佳答案

通过反复试验:

# invisible
withVisible(invisible())$visible
[1] FALSE

### passing the invisible value through a function seems to
# preserve the invisibility
withVisible(identity(invisible()))$visible
[1] FALSE

# the <- operator just returns its arguments, so it confirms the above
withVisible(i <- invisible())$visible
[1] FALSE
# but the assigned value is no longer invisible
withVisible(i)$visible
[1] TRUE

### passing an invisible value as argument keeps the invisibility
f <- function(x) withVisible(x)$visible
f(1)
[1] TRUE
f(invisible(1))
[1] FALSE

### every other operation seems to cancel the invisibility.
# e.g. assigning an invisible value cancels the it
i <- invisible()
withVisible(i)$visible
[1] TRUE

withVisible(invisible(1) + 1)$visible
[1] TRUE

关于r - invisible() 返回的对象何时不再不可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32573848/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com