Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R中为函数参数添加选项?也就是说,当用户点击选项卡时,他们会看到参数可以采用的所有可能值_R_Rstudio - Fatal编程技术网

如何在R中为函数参数添加选项?也就是说,当用户点击选项卡时,他们会看到参数可以采用的所有可能值

如何在R中为函数参数添加选项?也就是说,当用户点击选项卡时,他们会看到参数可以采用的所有可能值,r,rstudio,R,Rstudio,假设我有一个参数为x的函数 func<-function(x){ if(x=='a'){.......} else if (x=='b'){........} else if (x=='c'){.........} } func我假设您指的是RStudio中的控制台。我的理解是,这目前不是RStudio的一个功能。也许有人开发了一个可以为您实现这一点的控制台。我想您指的是RStudio中的控制台。我的理解是,这目前不是RStudio的一个功能。也许有人已经开发了一

假设我有一个参数为x的函数

func<-function(x){
    if(x=='a'){.......}
    else if (x=='b'){........}
    else if (x=='c'){.........}
}

func我假设您指的是RStudio中的控制台。我的理解是,这目前不是RStudio的一个功能。也许有人开发了一个可以为您实现这一点的控制台。

我想您指的是RStudio中的控制台。我的理解是,这目前不是RStudio的一个功能。也许有人已经开发了一个可以为您实现这一点的软件包。

您可以创建一个软件包,并将文档添加到您的函数中。例如,您可以运行
devtools::create(“~/mypackage”)
(如果需要,可以更改
~/mypackage
)。然后在
~/mypackage/R
创建一个名为
myfunc.R
的文件。在该文件中,设置以下内容

#' @title What does this function do?
#' @param x if \code{a} then 1, if \code{b} then 2, if \code{c} then 3.
#' @param ... may have an effect in the future.
#' @export
myfunc <- function(x, ...){
  if(x=='a'){
    1
  }
  else if (x=='b'){
    2
  }
  else if (x=='c'){
    3
  } else
    stop(sQuote(x), " not implemented")
}
#@title此函数的作用是什么?
#'@param x if\code{a}那么1,if\code{b}那么2,if\code{c}那么3。
#“@param。。。将来可能会有影响。
#“@出口

myfunc您可以创建一个包并向函数中添加文档。例如,您可以运行
devtools::create(“~/mypackage”)
(如果需要,可以更改
~/mypackage
)。然后在
~/mypackage/R
创建一个名为
myfunc.R
的文件。在该文件中,设置以下内容

#' @title What does this function do?
#' @param x if \code{a} then 1, if \code{b} then 2, if \code{c} then 3.
#' @param ... may have an effect in the future.
#' @export
myfunc <- function(x, ...){
  if(x=='a'){
    1
  }
  else if (x=='b'){
    2
  }
  else if (x=='c'){
    3
  } else
    stop(sQuote(x), " not implemented")
}
#@title此函数的作用是什么?
#'@param x if\code{a}那么1,if\code{b}那么2,if\code{c}那么3。
#“@param。。。将来可能会有影响。
#“@出口
myfunc