R package to generate Universally Unique Identifiers (UUIDs) version 4 and 5 using Boost C++ library.
To install the package from the CRAN run the following command:
Also you could install the dev-version with the install_gitlab()
function from the remotes
package:
This package contains the compiled code, therefore you have to use the Rtools to install it on Windows.
Generate single UUID:
Generate multiple UUIDs:
RcppUUID::uuid_generate_random(5)
#> [1] "2f669c10-2ad7-461b-a531-103bafed0b15" "fbe4959e-c723-4670-a155-f440c753c509" "074c5472-b314-4e4f-9aab-88bfc72f030a"
#> [4] "ad9ebe8c-4b85-4819-b1bd-6091a2305024" "d5287bae-666c-448b-bcb9-2e41fc173540"
Check uniques for the uuids:
unique_n <- function(x) length(unique(x))
n <- 1000000
unique_n(RcppUUID::uuid_generate_random(n)) == n
#> [1] TRUE
Benchmarking:
Single UUID:
microbenchmark::microbenchmark(
uuid = uuid::UUIDgenerate(FALSE),
RcppUUID = RcppUUID::uuid_generate_random()
)
#> Unit: microseconds
#> expr min lq mean median uq max neval
#> uuid 15.532 16.0670 44.47824 16.2875 16.5985 2794.521 100
#> RcppUUID 8.166 8.6705 9.36236 9.4465 9.7080 19.991 100
Multiple UUIDs:
n <- 10000
microbenchmark::microbenchmark(
uuid = uuid::UUIDgenerate(FALSE, n),
RcppUUID = RcppUUID::uuid_generate_random(n)
)
#> Unit: milliseconds
#> expr min lq mean median uq max neval
#> uuid 74.147780 77.636038 87.449953 79.408061 81.066626 304.77218 100
#> RcppUUID 7.956943 8.725376 9.133505 9.101491 9.452271 11.24261 100
Generate version UUIDs based on the text input:
RcppUUID::uuid_generate_name(letters[1:5])
#> [1] "54a0a790-c611-5b5b-b50e-ff01490ecdfa" "d5080e36-1ba4-5cb3-861c-34b25868f7db" "33ed51b6-a330-5830-bda9-2bac09e15753"
#> [4] "b74b2afe-06d5-5fea-99cc-a7de0b492704" "8535136c-b0d3-5373-aa79-ab67d33a2a8e"
For the each unique input will be generated unique UUID. Check uniqueness:
uuids <- replicate(10, RcppUUID::uuid_generate_name(letters))
length(unique(as.vector(uuids))) == length(letters)
#> [1] TRUE
RcppUUID::uuid_validate(NA_character_)
#> [1] FALSE
RcppUUID::uuid_validate("")
#> [1] FALSE
RcppUUID::uuid_validate("not uuid")
#> [1] FALSE
RcppUUID::uuid_validate(RcppUUID::uuid_generate_random(5))
#> [1] TRUE TRUE TRUE TRUE TRUE
RcppUUID::uuid_validate(RcppUUID::uuid_generate_nil(5))
#> [1] TRUE TRUE TRUE TRUE TRUE
RcppUUID::uuid_validate(RcppUUID::uuid_generate_name(letters[1:5]))
#> [1] TRUE TRUE TRUE TRUE TRUE
Use the following command to go to the page for bug report submissions:
Before reporting a bug or submitting an issue, please do the following:
news(package = "RcppUUID", Version == packageVersion("RcppUUID"))
command;RcppUUID
package, not from other packages;Please attach traceback() and sessionInfo() output to bug report. It may save a lot of time.
The RcppUUID
package is distributed under GPLv2 license.