title: for loop over a code without encountering the error
body: <p>I have a chunk of r code, like below.</p>
  
  <pre><code>sce_1$use &lt;- cellFilter(sce_1, 2500, 1000, 5)
  sce_2$use &lt;- cellFilter(sce_2, 2500, 1000, 5)
  sce_3$use &lt;- cellFilter(sce_3, 2500, 1000, 5)
  sce_4$use &lt;- cellFilter(sce_4, 3000, 1000, 5)
  sce_5$use &lt;- cellFilter(sce_5, 3000, 1000, 5)
  </code></pre>
  
  <p>This code works fine without any error or warning. To automate and clean the process I am trying to put this in a loop.</p>
  
  <pre><code>    sce_list=mget(sce)
      for (i in 1:length(paths))
      sce_list[i]$use &lt;- cellFilter(sce_list[i], 3000, 1000, 5)
  
      The error I get
  
      Quitting from lines 209-213 (prototype.Rmd) 
      Error in sce$total_features : $ operator is invalid for atomic vectors
      Calls: &lt;Anonymous&gt; ... eval -&gt; eval -&gt; cellFilter -&gt; filter_by_expr_features
      Execution halted 
  </code></pre>
  
  <p>What else I have tried is:</p>
  
  <pre><code>    sce_list=mget(sce)
      for (i in 1:length(paths))
       get(paste0("sce_",i))$use &lt;- cellFilter(sce[i], 2500, 1000, 5)
  
  the error I get is
  
  Quitting from lines 209-213 (prototype.Rmd) 
  Error in sce$total_features : $ operator is invalid for atomic vectors
  Calls: &lt;Anonymous&gt; ... eval -&gt; eval -&gt; cellFilter -&gt; filter_by_expr_features
  Execution halted
  </code></pre>
  
  <p>On one of the suggestions from the comments, I used:</p>
  
  <pre><code>sce_list=mget(sce)
      for (i in 1:length(paths))
       sce_list[[i]]$use &lt;- cellFilter(sce_list[[i]], 2500, 1000, 5)
  </code></pre>
  
  <p>This works fine. However, the next chunk of code that uses the previous part and used to work fine without looping of the previous chunk. However, now it throws up error.</p>
  
  <pre><code>automateFiltering &lt;- function(sce){
  
      options(repr.plot.width=4, repr.plot.height=4)
      plotPCA(
          sce,
          size_by = "total_features", 
          pca_data_input = "pdata",
          shape_by = "use",
          detect_outliers = TRUE,
          return_SCE = TRUE
      )
  }
  
  sce_1 &lt;- automateFiltering(sce_1)
   sce_2 &lt;- automateFiltering(sce_2)
     sce_3 &lt;- automateFiltering(sce_3)
      sce_4 &lt;- automateFiltering(sce_4) 
  </code></pre>
  
  <p>error:</p>
  
  <pre><code>    Quitting from lines 241-246 (prototype.Rmd) 
  Error in .choose_vis_values(object, shape_by, cell_control_default = TRUE,  : 
    'use' not found in 'colnames(colData(x))'
  Calls: &lt;Anonymous&gt; ... plotPCA -&gt; .local -&gt; plotReducedDim -&gt; .choose_vis_values
  Execution halted
  </code></pre>