更改内置函数中的默认值 [英] Change the default value in a built-in function

查看:107
本文介绍了更改内置函数中的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以更改R中内置函数的默认值?我发现了一些有关在R中为用户设置的函数设置默认值的问题,但对于内置函数却没有设置。

I was wondering if it is possible to change the default value for a built-in function in R? I have found some questions about setting default values for user made functions in R, but not for built-in functions.

为什么要这样做?老实说,这纯粹是为了方便。有时,我会将结果/数据写入.csv文件,以便在Excel中制作一些快速图形。为此,我使用 write.csv 函数。此函数的默认值之一是 row.names = TRUE 。到目前为止,我从来没有想要过Excel文件中的row.name,而且我忘记将 row.names = FALSE 添加到函数数十次了。那么是否可以将此函数的默认值更改为 row.names = FALSE

Why do I want this? To be honest, it is purely a matter of convenience. Sometimes I write my results/data to a .csv file to make some quick graphs in Excel. To do this I use the write.csv function. One of the defaults in this function is row.names = TRUE. So far, I have never wanted the row.names in my Excel file and I have forgotten to add row.names = FALSE to the function dozens of times. So is it possible to change the default value in this function to row.names = FALSE?

推荐答案

否。但是,如果您想方便起见,请自己编写包装函数。例如:

No. But if you want convenience, write a wrapper function yourself. For example:

my_write.csv <- function(...) write.csv(..., row.names = FALSE)

然后使用 my_write.csv

这篇关于更改内置函数中的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆