【发布时间】:2017-11-29 10:54:57
【问题描述】:
所以我想在脚本的多个位置使用一个函数,但我不想一遍又一遍地重复脚本部分。我可以将它分配给这样的变量吗?
png(filename = "comparison_plot.png",
units = "px",
width = 1920,
height = 1080,
res = 150,
bg = "white",
type = "cairo")
function <- png(filename = "comparison_plot.png",
units = "px",
width = 1920,
height = 1080,
res = 150,
bg = "white",
type = "cairo")
然后当我稍后在脚本中使用它时:
>function
它将调用该函数并执行我编写的代码:
png(filename = "comparison_plot.png",
units = "px",
width = 1920,
height = 1080,
res = 150,
bg = "white",
type = "cairo")
谢谢大家!
【问题讨论】:
-
你快到了。如果您不更改函数中的参数,您可以创建一个带有空参数列表的函数。因此,您的代码将如下所示:
myfun <- function() {mycode}.
标签: r variable-assignment