| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/session.R |
| 3 |
\name{do_once} |
| 4 |
\alias{do_once} |
| 5 |
\title{Perform a task once in an R session} |
| 6 |
\usage{ |
| 7 |
do_once( |
| 8 |
task, |
| 9 |
option, |
| 10 |
hint = c("You will not see this message again in this R session.", |
| 11 |
"If you never want to see this message,", |
| 12 |
sprintf("you may set options(\%s = FALSE) in your .Rprofile.", option)) |
| 13 |
) |
| 14 |
} |
| 15 |
\arguments{ |
| 16 |
\item{task}{Any R code expression to be evaluated once to perform a task, |
| 17 |
e.g., \code{warning('Danger!')} or \code{message('Today is ', Sys.Date())}.} |
| 18 |
|
| 19 |
\item{option}{An R option name. This name should be as unique as possible in |
| 20 |
\code{\link[=options]{options()}}. After the task has been successfully performed, |
| 21 |
this option will be set to \code{FALSE} in the current R session, to |
| 22 |
prevent the task from being performed again the next time when |
| 23 |
\code{do_once()} is called.} |
| 24 |
|
| 25 |
\item{hint}{A character vector to provide a hint to users on how not to |
| 26 |
perform the task or see the message again in the current R session. Set |
| 27 |
\code{hint = ""} if you do not want to provide the hint.} |
| 28 |
} |
| 29 |
\value{ |
| 30 |
The value returned by the \code{task}, invisibly. |
| 31 |
} |
| 32 |
\description{ |
| 33 |
Perform a task once in an R session, e.g., emit a message or warning. Then |
| 34 |
give users an optional hint on how not to perform this task at all. |
| 35 |
} |
| 36 |
\examples{ |
| 37 |
do_once(message("Today's date is ", Sys.Date()), "xfun.date.reminder") |
| 38 |
# if you run it again, it will not emit the message again |
| 39 |
do_once(message("Today's date is ", Sys.Date()), "xfun.date.reminder") |
| 40 |
|
| 41 |
do_once({ |
| 42 |
Sys.sleep(2) |
| 43 |
1 + 1 |
| 44 |
}, "xfun.task.1plus1") |
| 45 |
do_once({ |
| 46 |
Sys.sleep(2) |
| 47 |
1 + 1 |
| 48 |
}, "xfun.task.1plus1") |
| 49 |
} |