【发布时间】:2022-01-10 20:55:23
【问题描述】:
我正在用 R 语言开发一个相对简单的包,其中包含几个可视化功能。现在我有一个名为 make_a_bargraph() 的函数,它有一个 colour 参数。我想要的是它也接受color(使用美式拼写)作为有效参数。所以基本上就像ggplot 一样,它的geoms 也是如此。
理想情况下,我们应该有这样的函数:
make_a_bargraph <- function(colour) {
#' @desc function to do something with the colour-argument
#' @param colour the colour to be printed
#' @return a printed string
print(colour)
}
# with the 'regular' call:
make_a_bargraph(colour = "#FF0000")
# and the desired output:
[1] FF0000
# but also this possibility with US spelling:
make_a_bargraph(color = "#FF0000")
# and the same desired output:
[1] FF0000
如何实现这一目标?
【问题讨论】:
标签: r function ggplot2 colors package