R 解包后粘贴()省略号赢得';不打印列出的参数

R 解包后粘贴()省略号赢得';不打印列出的参数,r,R,我创建了函数mad_libs,其中一个函数传递一个省略号作为参数并将其解包。函数“起作用”,因为它确实在打印,显然没有什么问题,但我没有得到我传递的参数 功能如下: mad_libs <- function(...){ args <- list(...) place <- args[["place"]] adjective <- args[["adjective"]]

我创建了函数
mad_libs
,其中一个函数传递一个省略号作为参数并将其解包。函数“起作用”,因为它确实在打印,显然没有什么问题,但我没有得到我传递的参数

功能如下:

   mad_libs <- function(...){
            args <- list(...)

            place <- args[["place"]]
            adjective <- args[["adjective"]]
            noun <- args[["noun"]]

            paste("News from", place, "today where", adjective, "students took 
to the streets in protest of the new", noun, "being installed on campus.")
    }
参数没有打印出来

我有打印问题,因为我的操作系统是Br葡萄牙语,但这似乎不是拼写规则会有问题的情况

用巴西葡萄牙语在RStudio和Windows10上运行R3.3.1。

您可能应该学习

如果希望位置匹配和名称匹配都起作用,可以使用
do.call
,如下所示:

mad_libs <- function(...){
  args <- list(...)

  fun <- function(place, adjective, noun)
    paste("News from", place, "today where", adjective, "students took to the streets in protest of the new", noun, "being installed on campus.")

  do.call(fun, args)
}

mad_libs("NIFLHEIM", "possessed", "fountain")
#[1] "News from NIFLHEIM today where possessed students took to the streets in protest of the new fountain being installed on campus."

mad_libs(adjective = "possessed", "NIFLHEIM", "fountain")
#[1] "News from NIFLHEIM today where possessed students took to the streets in protest of the new fountain being installed on campus."
你应该好好学习

如果希望位置匹配和名称匹配都起作用,可以使用
do.call
,如下所示:

mad_libs <- function(...){
  args <- list(...)

  fun <- function(place, adjective, noun)
    paste("News from", place, "today where", adjective, "students took to the streets in protest of the new", noun, "being installed on campus.")

  do.call(fun, args)
}

mad_libs("NIFLHEIM", "possessed", "fountain")
#[1] "News from NIFLHEIM today where possessed students took to the streets in protest of the new fountain being installed on campus."

mad_libs(adjective = "possessed", "NIFLHEIM", "fountain")
#[1] "News from NIFLHEIM today where possessed students took to the streets in protest of the new fountain being installed on campus."

这对我来说很好。我试过mad_libs(place=“the moon”,形容词=“hyperactive”,名词=“SAS数据服务器”)。您是否指定了传递给
mad_libs
的参数?不,我没有。我只尝试了位置匹配。命名参数确实有效,但我不明白为什么不这样做。它对我来说很好。我试过mad_libs(place=“the moon”,形容词=“hyperactive”,名词=“SAS数据服务器”)。您是否指定了传递给
mad_libs
的参数?不,我没有。我只尝试了位置匹配。它确实可以命名参数,但我不明白为什么它不能以其他方式命名。正如您所提到的,我正在研究参数匹配,并且还解包了省略号。你的解决方案看起来比我尝试的更有趣,也更经济。谢谢你的帮助!正如你提到的,我在研究参数匹配,也在研究省略号的解包。你的解决方案看起来比我尝试的更有趣,也更经济。谢谢你的帮助!
mad_libs <- function(...){

  fun <- function(place, adjective, noun)
    paste("News from", place, "today where", adjective, "students took to the streets in protest of the new", noun, "being installed on campus.")

  fun(...)
}