Summary

Check that you can organize an R project, distinguish objects in memory from files on disk, and use packages deliberately.

Before you start: running R commands.
Setup: Use your own RStudio project. Its file-free check does not require an input CSV.
Your check: Reopen a project, run a script and explain the session information. Practise in the unit summary.

What you learned

Concept Meaning Practical consequence
Workspace Objects held in the running R session. An object in the Environment pane is not automatically a saved data file.
Working directory The folder from which R resolves relative file paths. Check it with getwd() before reading or writing files.
RStudio project A project folder associated with an .Rproj file. Opening it starts work in that folder; a later setwd() can change the working directory.
Relative path A location described from the working directory. Data/observations.csv means a file inside its Data subfolder.
Absolute path A location beginning at the filesystem root or drive. A path from your own computer may not work for another person.
Package A collection of functions, documentation, and sometimes data. Installation and loading are different steps.

Keep unchanged inputs in Data/ and generated exports, plots and reports in Output/. Record processing steps in scripts; a small project’s script can sit beside its .Rproj. For a larger project, Process/ is an optional place for scripts and intermediate work. When the project root is the working directory, a script saved in Process/ still reads Data/file.csv relative to the project root, not relative to the script file.

A short recap in R

These commands inspect the session and construct a path; they do not create or import a file.

getwd()
input_file <- file.path("Data", "observations.csv")
input_file
sessionInfo()

file.path() joins folder and file names using the appropriate separator. sessionInfo() records the R version, platform, and attached or loaded packages, which helps explain differences between computers. The output depends on your session.

Working with packages

Install an additional package with install.packages("package_name"), replacing the placeholder with its actual name. Installation puts it into an R library on disk and is usually needed once per R installation or library, with updates when appropriate. Load it with library(package_name) in each session that needs its functions. package_name::function_name() calls an exported function explicitly without attaching the whole package; the package must still be installed.

Save scripts and required data rather than relying on a restored workspace to supply objects you forgot to create. Run a script in a fresh session to find hidden dependencies on earlier interactive work.

Try it yourself

For this practice, try the larger-project arrangement: in an RStudio project, create Data/, Process/ and Output/ folders if needed. Save a script as Process/session-check.R that creates marker <- 42 and calls getwd() and sessionInfo(). Close and reopen the .Rproj, restart R, and run the saved script. Construct the path to Data/observations.csv without reading a file.

Compare the checks
marker <- 42
getwd()
input_file <- file.path("Data", "observations.csv")
input_file
sessionInfo()

The working directory should be the folder containing the .Rproj, not Process/. The constructed path is relative to that root; it does not create a CSV. marker is an R object, while Process/session-check.R is a file. Session output varies by computer. The package lesson has a separate optional install/call/restart check.

Ready to continue: you can reopen the project, recreate an object from its script and explain where a relative path starts.

Check your understanding

Try these questions before opening the suggested answers.

  1. Does deleting an object from the workspace delete its source CSV file? Explain why.
  2. If the working directory is the project root, where does Data/observations.csv point when your script is in Process/?
  3. A package is installed, but a function is unavailable by its short name. What could you check or do next?
Suggested answers
  1. No. Removing an R object changes the running workspace; its source CSV remains on disk. Conversely, closing R without saving an object does not erase your saved script.
  2. It points to Data/observations.csv inside the project root. The script’s Process/ location does not determine where a relative path starts; getwd() does.
  3. Check the spelling and package documentation. Attach an installed package with library() or call an exported function using package::function(). Also check the library/version when installations differ; reinstalling is not the first solution to every missing function.

Revisit the work environment and packages if needed.

Updated: