Little useless-useful R functions โ QR-Code Clock
R-bloggers 2025-01-08
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Ever wanted to have a clock on the wall or in the office, that is not binary. But it is QR-Code clock Well, now you can have it.
This useless R function generates new QR Code for every given period and tells the time. Run this function:
library(qrcode)while (Sys.time()+1 > Sys.time()){ n_o_w <- paste0("Current time is ",as.character(format(Sys.time(), "%X"))) print(n_o_w) qr_code(n_o_w, ecl = "M" ) |> plot() Sys.sleep(10)}
The best part would be to get a small screen and a raspberry-pi and have this shown on the screen. Or create your favorite Power BI report with R element and copy paste this code and set to refresh report on given period.
And the QRCodes in the clock are the following time stamps:
[1] "Current time is 18:39:42"[1] "Current time is 18:39:43"[1] "Current time is 18:39:44"[1] "Current time is 18:39:45"[1] "Current time is 18:39:47"[1] "Current time is 18:39:48"[1] "Current time is 18:39:49"[1] "Current time is 18:39:50"[1] "Current time is 18:39:51"[1] "Current time is 18:39:52"
Additional code for creating animation
# creating animationlibrary(gganimate)getwd()setwd("/Users/tomazkastrun/Documents/tomaztk_github/Useless_R_functions/figures")for (i in 1:10){ n_o_w <- paste0("Current time is ",as.character(format(Sys.time(), "%X"))) print(n_o_w) qr <- qr_code(n_o_w, ecl = "M" ) filename <- paste0("QRCode", i, ".png") png(filename) plot(qr) dev.off() Sys.sleep(1)}library(magick)files <- c("QRCode1.png", "QRCode2.png", "QRCode3.png", "QRCode4.png", "QRCode5.png", "QRCode6.png", "QRCode7.png", "QRCode8.png", "QRCode9.png", "QRCode10.png")images <- image_read(files)animation <- image_animate(images, fps = 1) image_write(animation, "QRCode_animation.gif")
As always, the complete code is available on GitHub in ย Useless_R_function repository. The sample file in this repository isย hereย (filename:ย QR-Code_clock.R). Check the repository for future updates.
Carry on with R-coding and stay healthy!
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.