实例 R 语言 在函数内部创建一个与全局变量同名的变量

x
 
txt <- "global variable"
my_function <- function() {
  txt = "fantastic"
  paste("R is", txt)
}
my_function()
txt # print txt
                    

输出结果

[1] "R is fantastic"
[1] "global variable"