This seems like a straight forward question, but I am having trouble finding a solution.
I want to input a variable at the top of my script and use that variable subsequently in the code to name or call saved objects in the environment. For looking at a specific ID (say 2174 or 2185 in these examples) I'd like to have the ID entered at the beginning of the script, then call it based on the variable name in the environment. Then if I want to change my subject ID, the subsequent code won't need change because it's calling the ID from the saved variable.
In python, it looks something like this:
#enter mouse number you want to analyze
mouse = "2174"
working_dir = r"D:/Mouse_" + mouse + "/iti_intervals" + "/"
#then the wd is D:/Mouse_2174/iti_intervals/
In MATLAB, you can do something like this:
mouse = 2185
sprintf('This is mouse number %d', mouse)
#this returns "This is mouse number 2185"
In R, what I want is something like this:
mouse <- 2185
#create variable listing all the files in chosen directory with trial summary files
trial_summ_(DIGIT FROM "mouse") <- list.files(path = assign("D:/Mouse_", get(mouse)), "/iti_intervals", recursive = TRUE, pattern = "trialsummary.txt", full.names = TRUE)
#to read as: trial_summ_2185 <- list.files(path = assign("D:/Mouse_2185/iti_intervals"...
I've tried using assign, paste0, and get, but none seem to do it correctly. I've also tried the variable name without a function and that fails.