Learn R Programming

QRcode Generator for R

A QR code is a two-dimensional barcode developed by the Denso Wave company.

The current implementation handles three modes: numeric, alphanumeric and byte. Kanji is currently not supported. Please contact the maintainer if you need it.

  • Numeric: only digits from 0 to 9
  • Alphanumeric: all numeric characters, upper case LETTERS, and the characters " " (space), "$", "%", "*", "+", "-", ".", "/" and ":"
  • Byte: All characters from the Latin 1 (ISO 8859-1) character set.

Main functions

The main qr_code() function returns an object of the qr_code class. This is a logical matrix with specific methods for printing and plotting. The print version uses UTF-8 drawing symbols and the result depend on the font used. For a better quality QR code it best to use plot() or generate_svg().

library(qrcode)
code <- qr_code("QR CODE")
print(code)
##               
##  ▗▄▄▄  ▗▗▄▄▄  
##  ▐▗▄▐ ▐▟▐▗▄▐  
##  ▐▐█▐▐▞▐▐▐█▐  
##  ▐▄▄▟▗▚▚▐▄▄▟  
##  ▗▖ ▄▖ ▖ ▗▖   
##  ▝▄▜▄▌▘▜▚▛▚█  
##  ▐▜█▚▀▐██▙▙▞  
##  ▗▄▄▄▐▄▞▖▗▟▄  
##  ▐▗▄▐▝▖▖▞▗▟▘  
##  ▐▐█▐ ▞█▛▄▐▄  
##  ▐▄▄▟▐▘▜▀▐▜▝  
##               
##               
## 
## use plot() for a better quality image
plot(code)
generate_svg(code, filename = "man/figures/qr.svg")

Installation

The qrcode package is available from CRAN, R universe and GitHub.

# install from CRAN
install.packages("qrcode")
# install from R universe
install.packages("qrcode", repos = "https://thierryo.r-universe.dev")
# install from GitHub use the remotes package
remotes::install_github("ThierryO/qrcode")

Legacy code

The legacy function qrcode_gen() had several known bugs. Because of these bugs, we re-implemented the code from scratch in version 0.1.4. We created new functions. The old functions are defunct since version 0.2.0. We removed them in version 0.2.2.

Copy Link

Version

Install

install.packages('qrcode')

Monthly Downloads

2,034

Version

0.3.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Last Published

September 29th, 2024

Functions in qrcode (0.3.0)

qr_matrix

Prepare matrices with default patterns and unmasked data A list with a matrix containing the default patterns (finder pattern, timing pattern, separators, alignment pattern and dark module), the unmask data pattern and the version.
qr_location

Create a QR code for a location
qr_wifi

Generate QR code with wifi login information
qr_version

Determine the required version Returns a list with the version, error correction level and mode. The bit string encodes mode and the length of the input string.
qr_vcard

Create a QR code for a vCard
qr_mode

Determine the required mode
qr_code

Generate the QR code
qr_encode

Create the bit encoding
qr_sepa

Generate a QR code for a SEPA payment
bits2int

Convert a bits object to an integer and vice versa
generate_svg

Generate the QR code as an svg file
add_logo

Add a logo to a QR code
coordinates

Extract coordinates from a QR code object.
print.bits

Print a bits vector Display the logical vector as a bit string where FALSE is shown as 0 and TRUE as 1.
bits

Create a bits object
c.bits

Combine bits
plot.qr_code

Plot the QR code This function plots to QR code to the open device.
print.qr_code

Print the qr_code object
as.character.bits

Convert a bits object into a character string
qr_error

Create the message and error code bit string
qr_event

Generate a QR code for an event