Tom
Tom

Reputation: 2351

Printing to console from a function within a function

I would like to make this function within a function print to console:

somefun <- function(x) {
    otherfun <- function (x) {
        print(x)
    }
}
somefun("It works!")

What would be the best way to make this happen?

Upvotes: 0

Views: 67

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389275

Call the inner function in the outer function?

somefun <- function(x) {
  otherfun <- function (x) {
    print(x)
  }
  otherfun(x)
}

somefun("It works!")
#[1] "It works!"

Upvotes: 1

Related Questions