2

I have a laboratory analyzer that generates results in a .csv or .xlsx format, however right now I must manually type the results from the output into our result tracking software system manually because copy-paste doesn't work.

I would like to write an R script that can translate the results from this .csv into the software program, and the best way I can think of is to generate the results as a barcode/QR code which I can then scan in to the software program. To do this, I need a tab-delimited output to be contained within the QR code. So far, I can generate a QR code using the package qrcode result-by-result, but if I have 50+ results, I can't generate a QR code for each, and I can't figure out how to get the qrcode package to give me what I need.

# Example dataframe
test <- LETTERS[1:10]
result.one <- rnorm(1:10)
result.two <- rnorm(1:10)
df <- data.frame(test, result.one, result.two)

Expected output is a QR code that can be scanned to generate results that look something like the output from this code:

library("openxlsx")
library("dplyr")
write.xlsx(select(df, test, result.one), file = "H:/R/junk1.xlsx")
write.xlsx(select(df, test, result.two), file = "H:/R/junk2.xlsx")

where junk1 would be one QR code, junk2 would be another, etc...

If I can figure this out, I can save my staff hours of tedious work every day... so this would be a great help!

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
Dorton
  • 185
  • 1
  • 2
  • 11
  • 1
    How big is your data? And what data types? [This answer](https://stackoverflow.com/a/11065499/903061) says the maximum for alphanumeric data in a QR code is 4096 characters. Just want to make sure this will work for your real data too. – Gregor Thomas Jan 16 '19 at 02:32
  • There much be a much easier system if your unnamed software program has an API... – Gregor Thomas Jan 16 '19 at 02:32
  • Also I'm confused by *"I can generate a QR code using the package qrcode result-by-result, but if I have 50+ results, I can't generate a QR code for each"*. That seems like a contradiction. What is stopping you from generating a QR code for each? Is this a technical problem with R or something else? – Gregor Thomas Jan 16 '19 at 02:36
  • It would be really nice if you share the QR generating code you have so answerers have something to build on. – Gregor Thomas Jan 16 '19 at 02:36
  • My real data has 16 rows, and each column (i.e. result.one, result.two) correspond to a sample. The "result" columns contain numerical data for each row. It's actually a drug screen on an LC-MS (if that means anything to you). So each drug in the panel (test "A" to "J" in the example) has a corresponding numerical result (i.e. "25.1"). Sorry, no API output that I know of from this software. – Dorton Jan 16 '19 at 04:33
  • An example of how I can get the result out one by one is by adding this to the above code: `result <- df[2,3]` then `qrcode_gen(result)` The problem with that is the physical limitation that I would have 16 qr codes to scan for every result column. Which... fine, but that's a little dangerous that the wrong code could get scanned by accident. – Dorton Jan 16 '19 at 04:35

1 Answers1

0

I'm posting this as an answer to my own question, although I'm not going to accept it because I'm not completely doing what I want to. I would still prefer not to have to scan 16 qr codes for every result column, but this is all I can come up with right now.

I am generating a QR code for each result in the "result.one" column as a jpeg, then pasting the jpeg into a new column. In the end, I'm going to parse out each "result.X" column and paste this output as a new table for each result. If anyone has a better approach, I'm all ears!

Using r-markdown

---
title: "QR Code in Column"
author: "dorton"
date: "2019/01/20"
output: html_document
---

library(qrcode)
library(knitr)

#Generate the data frame
test <- LETTERS[1:10]
result.one <- round(rnorm(1:10),2)
df <- data.frame(test, result.one, stringsAsFactors = FALSE)
df$result.one <- as.character(df$result.one) # qrcode_gen requires a character

#Generate a qrcode for each test in df$test
#Requires defining an output folder and writing a new jpeg for each qrcode (not ideal)
for(i in 1:length(df$test)){

  mypath <- file.path("path/name", "qrs", paste(df$test[i], ".jpg", sep = "")) 

  jpeg(file=mypath)
  sapply(df$result.one, function(x) qrcode_gen(df$result.one[i]))
  dev.off()
}

df$QRCodes <- paste0('![]','(path/name/', df$test, '.jpg)', '{width=0.5in}') #making the width 0.5 inches so it's readable

kable(df)

Dorton
  • 185
  • 1
  • 2
  • 11