1

According to the R Language Definition (version 3.0.2),

The value returned by a loop statement statement is always NULL and is returned invisibly.

(sec. 3.2.2 "Looping")

What does it mean for a value to be returned invisibly?

Filburt
  • 17,626
  • 12
  • 64
  • 115
Evan Aad
  • 5,699
  • 6
  • 25
  • 36
  • @SeñorO the question is not really asking what the function `invisible` does (though the question is inextricably linked to that function). I don't think it falls under *exact duplicate* (though I could be misinterpreting). – Simon O'Hanlon Dec 16 '13 at 22:30
  • @SimonO101 I think you're right - but I think the **answer** to this question will inevitably be an exact duplicate. – Señor O Dec 17 '13 at 16:17

1 Answers1

3

All functions must return something. invisible means the return value isn't visible to the user. Consider the simple function below:

f <- function(){
    x <- 2
    return( x )
}

#  Returns 2..
> f()
[1] 2

#  Returns 2 but you can't see it
f <- function(){
    x <- 2
    return( invisible(x) )
}

> f()
> 
#  But it is still returned...

str(f())
#num 2

You can see the return value of a for loop like so for example...

str( for( i in 1:3 ){} )
# NULL

Even invisible itself must return something...

str( invisible() )
# NULL
Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184