3

Is it possible to set an options to NULL while using getOption with a default value other than NULL?

options("TEST" = NULL)
getOption("TEST")
# NULL

getOption("TEST", default=1)
# [1] 1

I would have expected the last line to return NULL. Is this intended behavior.

Ricardo Saporta
  • 54,400
  • 17
  • 144
  • 178

2 Answers2

2

options is a named list, so setting an option to NULL is akin to removing that option.

It appears there is no way to have an option set to NULL while also allowing the use of getOption with an alternate default value.

Ricardo Saporta
  • 54,400
  • 17
  • 144
  • 178
2

Workaround: nest the (potentially NULL) value in a list and use that:

options(TEST = list(NULL))
getOption("TEST")[[1]]
# [1] NULL

getOption("TEST", default = list(1))[[1]]
# [1] NULL
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214