Create a QR code for FREE using R
R is a very versatile programming language and can do many graphical tasks with ease. Here, I demonstrate how to use R to generate QRcodes. These codes are useful for sharing hyperlinks in presentation slides, posters and flyers.
The qrcode R package can do exactly that. The documentation can be found on GitHub here.
The package can be installed from the CRAN package manager in the standard way:
install.packages("qrcode")
Once it is installed, load the package using the library command:
library(qrcode)
Now you can give it some data to make a QR code. Here I'm using this blog's URL.
code <- qr_code("https://genomespot.blogspot.com")
Next, you can output the code graphically. The print() command will print it in the terminal which is a bit ugly. The plot() command will pop up a window with the code.
print(code)
plot(code)
Now this generates a simple black and white QR code which might be sufficient for you. You can just grab a screenshot and paste it where you need it. However I would recommend that you also save a SVG file of the QR code which will retain the high resolution unlike a standard screenshot.
This also gives you the ability to tweak the colours to suit your application.
generate_svg(code,filename ="myqrcode.svg",
foreground = "green", background = "gold")
This package also allows you to include a logo in the QR code, which is normally a feature that requires a paid subscription. Here you can do it for free in R.
First generate the QR code as per normal, except specify ecl="H" which specifies a high error correction level.
code2 <- qr_code("https://genomespot.blogspot.com", ecl="H")
Next, add the logo from a source SVG file, specifying a lower error correction level.
code2 <- add_logo(code2,logo="thumbs-up-svgrepo-com.svg",ecl="L")
Then finally generate the QCcode with the logo
generate_svg(code2,filename ="myqrcode.svg",
foreground = "orange", background = "white")
Have fun!


