Body: <p>I have a set of files based on which I expect to load RDS files like R1-Tn5-NHP-55_NA and R1-Tn5-NHP-42_NA but the code is producing just the name of the 55 files not both 55 and 42.</p>
  <pre class="lang-r prettyprint-override"><code>#standardize N set names  
  rename_KP_set &lt;- function(sample_name_vector)  {
   new_sample_name_vector &lt;- apply(sample_name_vector, 
        function(x){     
           if (grepl(&quot;42&quot;,x[3])){     
             c(x[1:3],'55',x[5])
           } else if (grepl(&quot;55&quot;,x[3])) {
             c(x[1:3],'NHP',x[5])    
           } else if (grepl(&quot;55&quot;,x[3])){
             c(x[1:3],'NHP',x[5])
   } else
  c(x[1:3],'55',x[5])
   }  
  }) %&gt;% 
       sapply(paste, collapse='-')   
       return(new_sample_name_vector) 
   }
  </code></pre>
  <p>How I can get separate rds files having 42 and 55 numbers or for that matter any rds with some number attached to them?</p>
  <p>I have already <a href="https://stackoverflow.com/questions/75548867/naming-function-in-r">posted this question on Stack overflow on February 27th, 2023</a> but have got no answers so I am reposting that in Stack exchange bioinformatics in search of an answer. Any help on this issue will be considered useful.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-03-06T20:53:40.197Z
Comments.Text: Your question has a few wording issues. For example, what do you mean by "...a set of files based on which I expect to load RDS files..."? Provide sample input, expected output and actual output. You'll probably figure out the problem on your own as you prepare these items.
Comments.UserDisplayName: Ram RS
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-03-07T10:47:34.530Z
Comments.Text: Please [edit] your question and provide us with input files and expected output so we can reproduce the problem and test our solutions. We cannot work on a problem if we cannot reproduce it.
Comments.UserDisplayName: terdon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-03-07T18:21:20.537Z
Comments.Text: Can you please explain what your function is trying to do? It's not clear to me from just looking at the function.
Comments.UserDisplayName: gringer
Tags: <r>
Title: Naming functions in R
ThreadText: # Naming functions in R
  
  (Asked by: username_0 on 2023-03-06)
  
  I have a set of files based on which I expect to load RDS files like R1-Tn5-NHP-55\_NA and R1-Tn5-NHP-42\_NA but the code is producing just the name of the 55 files not both 55 and 42.
  
  ```r
  #standardize N set names  
  rename_KP_set <- function(sample_name_vector)  {
   new_sample_name_vector <- apply(sample_name_vector, 
        function(x){     
           if (grepl("42",x[3])){     
             c(x[1:3],'55',x[5])
           } else if (grepl("55",x[3])) {
             c(x[1:3],'NHP',x[5])    
           } else if (grepl("55",x[3])){
             c(x[1:3],'NHP',x[5])
   } else
  c(x[1:3],'55',x[5])
   }  
  }) %>% 
       sapply(paste, collapse='-')   
       return(new_sample_name_vector) 
   }
  
  ```
  
  How I can get separate rds files having 42 and 55 numbers or for that matter any rds with some number attached to them?
  
  I have already [posted this question on Stack overflow on February 27th, 2023](https://stackoverflow.com/questions/75548867/naming-function-in-r) but have got no answers so I am reposting that in Stack exchange bioinformatics in search of an answer. Any help on this issue will be considered useful.
  
  **Tags:** r
  
  > **Comments:**
  > **username_1**: Your question has a few wording issues. For example, what do you mean by "...a set of files based on which I expect to load RDS files..."? Provide sample input, expected output and actual output. You'll probably figure out the problem on your own as you prepare these items.  
  > **username_2**: Please [edit] your question and provide us with input files and expected output so we can reproduce the problem and test our solutions. We cannot work on a problem if we cannot reproduce it.  
  > **username_3**: Can you please explain what your function is trying to do? It's not clear to me from just looking at the function.  
  
  ---
  
  ## 0 answers
  
  