R function with no return value

后端 未结 5 434
滥情空心
滥情空心 2020-12-03 22:04

I was helping a friend of mine with some of his code. I didn\'t know how to explain the strange behavior, but I could tell him that his functions weren\'t explicitly returni

5条回答
  •  一向
    一向 (楼主)
    2020-12-03 22:49

    If you want a function to change the value of a variable in Global environment you can use <<- operator, but you still need to write the exact name of a variable in Global environment

    derp <- function(arg){
      arg <- arg+3
      b<<-3
    }
    

    Try it and call b

提交回复
热议问题