Advertisement
Guest User

Untitled

a guest
Jul 14th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.54 KB | None | 0 0
  1. library(glue)
  2.  
  3. participants <- c(1:30)
  4. tasks <-  c("a", "b", "c")
  5. sessions <- c(1:20)
  6.  
  7. # Loop through participants, task, sessions
  8. for (id in participants) {
  9.   for (task in tasks) {
  10.     for (session in sessions) {
  11.      
  12.       # Set an individual filename
  13.       file_name <- file(glue("P{id}_T{task}_S{session}.txt"))
  14.      
  15.       # Define the content of the text file
  16.       this_text <- "Your text here"
  17.      
  18.       # Write to file
  19.       writeLines(this_text, file_name)
  20.      
  21.       # Close file
  22.       close(file_name)
  23.     }
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement