barcode.R 880 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # * Author: Bangyou Zheng ([email protected])
  2. # * Created: 08:31 PM Thursday, 04 June 2015
  3. # * Copyright: AS IS
  4. # Generate barcode for a number
  5. zint_barcode <- function(
  6. labels,
  7. height = 50,
  8. border = 10,
  9. zint = 'zint',
  10. is_draw = FALSE,
  11. is_show_text = TRUE) {
  12. file_name <- paste0(tempfile(), '.png')
  13. res <- list()
  14. for (i in seq(along = labels)) {
  15. cmd <- paste0(
  16. zint,
  17. ' -o ', file_name,
  18. ifelse(is_show_text, '', ' --notext'),
  19. ' -b 20 --height=',
  20. height, ' --border=', border,
  21. ' -d "', labels[i], '"')
  22. system(cmd)
  23. library(png)
  24. img <- readPNG(file_name)
  25. res[[as.character(labels[i])]] <- img
  26. }
  27. if (is_draw) {
  28. library(grid)
  29. grid.raster(res[[1]])
  30. }
  31. res
  32. }