title: Run a script over multiple datasets
body: <p>i want to run a script over different datasets. Please see an illustrative example below. I defined a sort of parameters that tells R which dataset to use and how to name output. Now, i would like to have a loop to run the script for all datasets, i.e., first par1 =1 and then par2=1. Could you give some suggetions, please? Thanks in advance.   </p>
  
  <pre><code>library(MASS)
  library(ggplot2)
  library(xlsx)  
  
  # Parameters to define which dataset to use: 
    # if i want to use the dataset "beav1", i set par1 to 1 
    # if i want to use the dataset "beav2", i set par2 to 1
  
    par1 = 1  
    par2 = 0
  
   if(par1 == 1) {  
    df = beav1        # Load the dataset           
    Name = "beav1"    # Dynamic parameter for plots and output files        
    par1 = 0
   }
  
    if(par2 == 1){  
      df = beav2       # Load the dataset       
      Name = "beav2"   # Dynamic parameter for plots and output files    
      par2 = 0
    }
  
    # Make some data manipulation:  
    df = df[,2:3]
  
  
    # Plot results:  
    ggplot(df, aes(x=time,temp)) +  
      geom_line() +
      ggtitle(paste0(Name))
  
  
    # Save results in xlsx format:  
    write.xlsx(df, paste0(Name, ".xlsx"))
  </code></pre>