A student sends a collaborator a script whose first line is setwd("C:/Users/alex/Documents/stat101") and whose second line reads a CSV from a data subfolder. The collaborator, working on macOS, gets an error on line 1. Which response best addresses the underlying problem, rather than working around it?
Ask the collaborator to create the same folder structure at the same location on their machine, so that the existing path resolves.
Save the workspace as an .RData file after a successful run and send that instead, so the collaborator receives the finished objects.
Send the CSV file along with the script, so that the collaborator has the data the analysis needs.
Put the script and its data subfolder in an RStudio Project, delete the setwd() line, and use a project-relative path.
Unlock full course notes by signing up
Setting Up R & R Studio: difficulty 2
For each situation, give the single command or action that addresses it, and one sentence of justification.
You want to check which folder R will search when your script asks for a file using a relative path.
A collaborator using a different operating system must be able to run your analysis without editing any file paths.