stevec
stevec

Reputation: 52528

Create (and set value for) a new global option using base R?

Global options can be see with options(), or to just show the names names(options())

I can see a way to make new options of your choosing here

Is there a way to set a new global option so that it appears in the list generated with options() but without using an external library (i.e. just using base R)?

Note

I already know how to set a value for an option (e.g. options(max.print=200)), what I am specifically trying to do is create a new option altogether

Upvotes: 3

Views: 656

Answers (1)

NelsonGon
NelsonGon

Reputation: 13319

According to the documentation of options available via ?options or help(options), one can set a new option by specifying a name as a character and it's value. This is done using the ellipsis(...) argument(dots).

Note however, that the same documentation states that

any options can be defined, using name = value. However, only the ones below are used in base R.

Options can also be passed by giving a single unnamed argument which is a named list.

Therefore, we can create a new option say "my_print" as follows:

options(my_print=10)

We can then see that it is now under the list of available options:

options()$my_print
[1] 10

Note:

It is stated that R(base) will only use what it knows. If you then call options("my_print") you have a new option but whether it will work is questionable. This will also appear under options().

The list of options used by base R can be got by simply calling options() if you have not previously defined a new option. They are also available under the details section of the docs.

Upvotes: 3

Related Questions