title: How to process multiple Jpeg images in R
body: <p>I just started using RStudio, as the available package to analyze my images is in R. I just want to analyze some 50 images which are stored in a folder. How can I read each image (by forming a loop), perform some operation on each image and save the output (my output is a list) as a vector?   </p>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p>I just wrote a piece of code which is as following:</p>
  
  <pre><code>folder &lt;- "F:/F_diff/1_d/glass/New folder/"      # path to folder that holds multiple .jpg files
  file_list &lt;- list.files(path=folder, pattern="*.jpg") # create list of all .jpg files in folder
  
  for (i in 1:length(file_list)){
    assign(file_list[i],   
       #read image
       im2 &lt;- readImage(paste(folder, file_list[i], sep=''))
  
       #analyze each image
       B &lt;- matrix(im2,nrow=808,ncol=610,byrow=FALSE, dimnames=NULL)
       Haarimtest &lt;- TOS2D(B, smooth = FALSE, nsamples = 100)
       summary(Haarimtest)
  
   )}
  </code></pre>
  
  <p>I am getting the following errors:</p>
  
  <blockquote>
    <p>Error: unexpected symbol in:
    "         #analyze each image
             B"
             Haarimtest &lt;- TOS2D(B, smooth = FALSE, nsamples = 100)
    Error in base::log2(x) : non-numeric argument to mathematical function
             summary(Haarimtest)
    Error in summary(Haarimtest) : object 'Haarimtest' not found</p>
    
    <p>)}
    Error: unexpected ')' in "  )"</p>
  </blockquote>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>After some tinkering with the code and lot of searching, I was able to run it.
  The code first imports all 30 .tif images of size 64x64 pixels from a folder and perform some image analysis on each image
  The updated code is as follows:</p>
  
  <pre><code>&gt; library(tiff) 
    library(LS2W) 
    library(LS2Wstat)
  &gt; # path to folder that holds multiple .tif files 
    path &lt;- "C:/Users/Metaheuristics/Documents/MATLAB/diff_64 x64/2D/" 
  &gt; # create list of all .tif files in folder 
    files &lt;- list.files(path=path, pattern="*.tif") 
  &gt; 
  &gt; #import all files  
    for(file in files) {   
    perpos &lt;- which(strsplit(file, "")[[1]]==".")   
    assign(
  &gt; gsub(" ","",substr(file, 1, perpos-1)), 
  &gt; B&lt;-readTIFF(paste(path,file,sep="")))
  &gt; 
    #perform image analysis on individual images   
    Haarimtest &lt;- TOS2D(B, smooth = FALSE, nsamples = 100)            
    summary(Haarimtest)   
    }
  </code></pre>
  
  <p>Just one problem, I am not being able to save the result.  </p>