tjmahr / tjmahr.github.io

A responsive Jekyll theme with clean typography and support for large full page images.
https://tjmahr.github.io
MIT License
9 stars 8 forks source link

one-liner-to-generate-ids/ #8

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

A one-liner for generating random participant IDs - Higher Order Functions

Find a match() in your base R library

https://tjmahr.github.io/one-liner-to-generate-ids/

pjt222 commented 2 years ago

Hi Tristan,

thank you for this interesting post.

As an addition I would like to point to the ids package for creating random ids:

ids::random_id(n = 1, bytes = 3)
# "6a118f"

An alternative to the direct sprintf-call could be using formatC

a <- sprintf(paste0("p", "%0", 3, "d"), 1:3)
b <- paste0("p", formatC(1:3, width = 3, flag = "0"))

all.equal(a, b)

Best regards

tjmahr commented 2 years ago

An alternative to the direct sprintf-call could be using formatC

Thanks for the example. I don't think I have used formatC() before.