Tool
R
Python
Author

Tony D

Published

March 16, 2025

A guide to generating QR codes in R and Python.

This document demonstrates how to generate QR codes using both R and Python. It provides code examples for creating QR codes from a given string, saving them as SVG or PNG files, and displaying them. The R section uses the qrcode package, while the Python section uses the qrcode and scikit-image libraries.

R

Code
pak::pkg_install('qrcode')
Code
library(reticulate)
use_python("/Library/Frameworks/Python.framework/Versions/3.13/bin/python3.13")
py_require(c('qrcode','Pillow','numpy','scikit-image'))
Code
library(qrcode)
code=qr_code("https://rfor.us/posit2024slides") 

Save the QR code as a SVG file

Code
generate_svg(code, filename = "qr.svg")
Code
plot(code)

Python

Code
!pip install qrcode scikit-image
Code
import platform
print(platform.python_version())
3.13.2
Code
import qrcode
img = qrcode.make("https://rfor.us/posit2024slides")
type(img)  # qrcode.image.pil.PilImage
<class 'qrcode.image.pil.PilImage'>

save the QR code as a PNG file

Code
img.save("some_file.png")
Code
from skimage import io
img = io.imread("some_file.png")
io.imshow(img)