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

959

Version

0.2.2

License

GPL-3

Issues

Pull Requests

Stars

Forks

Last Published

November 11th, 2023

Functions in qrcode (0.2.2)

qr_mode

Determine the required mode
plot.qr_code

Plot the QR code This function plots to QR code to the open device.
qr_wifi

Generate QR code with wifi login information
qr_encode

Create the bit encoding
bits2int

Convert a bits object to an integer and vice versa
generate_svg

Generate the QR code as an svg file
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
coordinates

Extract coordinates from a QR code object.
c.bits

Combine bits
print.qr_code

Print the qr_code object
add_logo

Add a logo to a QR code
as.character.bits

Convert a bits object into a character string
qr_code

Generate the QR code
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_error

Create the message and error code bit string
qr_event

Generate a QR code for an event
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.