Skip to contents

The onetime package works by storing lockfiles in rappdirs::user_config_dir(). It won't do so unless permission has been granted. Before using onetime functions, package authors should call check_ok_to_store(ask = TRUE) in an interactive session, in functions which are called directly from the command line.

Usage

check_ok_to_store(
  ask = FALSE,
  message = "The onetime package requests to store files in '%s'.",
  confirm_prompt = "Is this OK? [Yn] ",
  confirm_answers = c("Y", "y", "Yes", "yes", "YES"),
  default_answer = "Y"
)

Arguments

ask

TRUE to ask the user for permission.

message

Message to display to the user.

confirm_prompt

Character string. Question to prompt the user to hide the message in future.

confirm_answers

Character vector. Answers which will cause the message to be hidden in future.

default_answer

Character string. Default answer if user simply presses return.

Value

TRUE if:

  • We already have permission;

  • ask is TRUE, we are in an interactive session and the user gives us permission;

  • options("onetime.dir") is set to a non-NULL value.

Otherwise FALSE.

Details

If your package is not used interactively, a workaround is to call set_ok_to_store(). This grants permission and prints an informative message. Package owners should only call this if they cannot ask explicitly.

onetime_message_confirm() is an exception: by default it doesn't require global permission to store files, since the user accepting "Don't show this again" is considered sufficient.

ask = TRUE asks the user, if he or she has not already given permission, and if the session is interactive().

Remaining parameters are passed to onetime_message_confirm() in this case, and ignored otherwise. A "%s" in message will be replaced by the onetime storage directory.

Examples


check_ok_to_store()
#> [1] FALSE