title: How to merge images into one file in a defined order
body: <p>I have around 100 images(png). Instead of doing that manually, I want to put them beside each other (12 images per line) in one single pdf in a defined order (based on file names).</p>
  
  <p>Does anybody have any suggestion?</p>
  
  <p>I tried according to what Thomas told me below, it paste them beside with a black margin, how can I remove that?</p>
  
  <pre><code>setwd(workingDir);
  files &lt;- list.files(path=".", pattern="*.png", all.files=T, full.names=T)
  filelist &lt;- lapply(files, readPNG)
  names(filelist) &lt;- paste0(basename((files)))
  list2env(filelist, envir=.GlobalEnv)
  
  
  par(mar=rep(0,4))
  layout(matrix(1:length(names(filelist)), ncol=15, byrow=TRUE))
  
  for(i in 1:length(names(filelist))) {
    img &lt;- readPNG(names(filelist[i]))
    plot(NA,xlim=0:1,ylim=0:1,xaxt="n",yaxt="n")
    rasterImage(img,0,0,1,1)
  }
  
  
  dev.print(pdf, "output.pdf") 
  </code></pre>