baRcodeR 1.1 preCRAN release a.k.a what are all these parameters for label layout?

[This article was first published on R on YIHAN WU, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The newest version of baRcodeR (v 1.1) is now on github as the development branch. At the moment, you can download the R package through

devtools::install_github("yihanwu/baRcodeR", ref = "development")

CRAN submission can take a long time (more than a month for baRcodeR’s first acceptance) and so I thought I would write a record of why I changed certain things for the future when I have to come back and add new features to old ones.

Horizontal and vertical spacing between label rows and columns

The biggest new feature in this release is the ability to specify the size of the spacing between labels. Essentially, the little strips of space between labels which gets left behind when the label is picked off. Originally, we did not include the horizontal and vertical spaces between labels. Page width, page height, the horizontal and the vertical page margins used to dictate the size of the labels. On our ULINE labels with horizontal spacing between labels (0.5 of an inch), the qr codes “crawled” leftwards for the columns on the right side of the page as the actual labels were slightly smaller than what was calculated.

So now, there are two new parameters for PDF creation, label_width and label_height. When label_width is specified, the horizontal spacing between each column of labels is calculated (since all labels will have a horizontal strip to the right except for the last column labels which have the horizontal margin instead.) The same with calculating the vertial spacing between each row using label_height. So if page_width = 8.5, the width_margin is 0.25 and there are 4 rows, the original calculated size of the label is (8.5 - 2 * 0.5)/2 or 3.75. Each label will start at 0.5, 2.5, 4.5, and 6.5 inches along the page.

But when label_width is supplied (1.75), we can calculate the horizontal space, (8.5 - 2* 0.5 - 4 * 1.75)/3 leaving behind 0.1666667 between each label.

Position of QR code and text label

ggplot2 was replaced by grid graphics for more precise control of location through viewports, though nothing on the interface has changed. (On a personal note, I learned so much about grid through removing the dependence on ggplot2). x_space and y_space, which control the location of the text , are now based on the size of the printed label.

Users will not be able to move the text further leftwards than the rightmost edge of the qrcode since that would actually disrupt the qrcode which would defeat the point of having a qrcode. But it can be moved to the right until it goes off the print label. Similarly the text label can move up or down.

I haven’t created any way of flipping the layout on each label, for example text on the left and qrcode on the right. It should be possible by changing the positions of the viewports in custom_create_PDF if anyone does not like the qrcode on the left. Similarly, I don’t know if there is any additional benefit if the qrcode is on top of the text or the reverse. While possible, I also did not add the ability print either the qrcode or the text label on their own, though both are certainly possible. I can see reasons to want only the text label on its own.

Lastly, the font size of the text can now be specified in points while it had previous been scaled. The limits on font size have also been removed, so it is possible to print page sized labels with big text labels. Right now, if truncation of long labels is not used, long labels that go off the label will be shrunk until they fit for a safeguard.

Why can’t the qrcode size be changed? It’s always relative to the label size.

Technically, the size can be changed through modifying the parameters in qr_vp within the custom_create_PDF code. But the list of parameters is already a lengthy one and I worry that smaller labels using a higher error correction would create printed qrcodes which cannot be read. Anti-aliased printing can sometimes work (since this seems to be a default PDF printing option for many people) but if it is tiny anti-aliased qrcodes … it would be a waste of label paper …

One last minor note

The qrcode package used to generate the actual qrcodes does not support the _ character. So all _ are replaced automatically by - for the qrcode though the _ will still show up in the text.

If you use underscores and then see dashes when using a barcode scanner, it is a limitation of the package dependency.

Possible future features

  • ability to print either qrcode or text on their own
  • label layouts (ie Staples, Avery, ULINE) included in package

To leave a comment for the author, please follow the link and comment on their blog: R on YIHAN WU. 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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)