Skip to content

Commit

Permalink
vectorized create_uid()
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinoa committed Nov 6, 2019
1 parent 9c0b597 commit 9172dca
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -7,6 +7,7 @@ export(admin_module_ui)
export(convert_timestamp)
export(create_app_user)
export(create_schema)
export(create_uid)
export(dashboard_module)
export(dashboard_module_ui)
export(firebase_dependencies)
Expand Down
30 changes: 27 additions & 3 deletions R/create_uid.R
Expand Up @@ -2,12 +2,36 @@
#'
#' user for the uids in the database
#'
#' @param n length 1 integer > 0. The number of uids to create.
#'
#' @return a character string uid
#'
#' @importFrom digest digest
#' @importFrom stats runif
#'
create_uid <- function() {
#' @export
#'
#' @examples
#'
#' # create a single uid
#' create_uid()
#'
#' # create 10 uids
#' create_uid(10)
#'
create_uid <- function(n = 1) {
stopifnot(length(n) == 1)
stopifnot(n > 0)

paste0("p", digest::digest(c(runif(1), Sys.time())))

paste0(
"p",
vdigest(runif(n))
)
}

#' vectorize the
#'
#' @importFrom digest digest
#'
#' @noRd
vdigest <- Vectorize(digest::digest)
14 changes: 13 additions & 1 deletion man/create_uid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9172dca

Please sign in to comment.