Code Context

Step-by-step guidance for each exercise. The original exercise prompt is shown as the title — click to expand for detailed instructions.


Versioning & Dependencies

Run the following in an iPython terminal or at the top of a notebook:

import sys
print(sys.version)

You should see something like 3.11.4 (main, ...). The first two numbers are the major and minor version — this is what matters most for compatibility.

Run the following in the R console:

R.version.string

You should see something like "R version 4.3.1 (2023-06-16)".

import pandas as pd
print(pd.__version__)

Or in a terminal:

pip show pandas
packageVersion("dplyr")

This is a reflection exercise — there’s no single right answer. Think about the imports at the top of your most-used scripts. Common examples:

numpy, matplotlib, scipy, seaborn, sklearn, biopython

ggplot2, tidyverse, DESeq2, Seurat, limma

Make a note of these — you’ll need them when setting up your environment for personal use.

In a terminal:

pip show pandas

Look for the Requires: line — this lists the packages pandas itself depends on (e.g. numpy, python-dateutil).

You can also browse pypi.org, search for your package, and look under Dependencies.

In the console:

tools::package_dependencies("dplyr")

Or browse cran.r-project.org, search for your package, and look at the Imports and Depends fields.


Environment management

The analysis folder contains two scripts:

  • spacewalk_analysis.py — Python version
  • spacewalk_analysis.R — R version

Open the file for your preferred language in your IDE. Have a read through — note which packages are imported at the top. These are what you’ll need to install into your new environment.

Open a terminal and run:

conda create --name spacewalk python=3.11

When prompted, type y and press Enter to confirm. Once created, activate it:

conda activate spacewalk

You should see (spacewalk) appear at the start of your terminal prompt — this confirms you’re working inside the new environment.

Open RStudio and make sure you have the analysis folder open as a project (FileNew ProjectExisting Directory).

Then in the console:

install.packages("renv")
renv::init()

renv will scan your project, set up a local library, and create a renv.lock file. You only need to do this once per project.

Check the import or library() statements at the top of your script to identify what needs installing.

With your environment active ((spacewalk) visible in the terminal):

conda install pandas matplotlib numpy

If any packages aren’t available via conda, use pip instead:

pip install package-name

To confirm a package installed correctly:

conda list

With your renv-enabled project open in RStudio, install packages as normal:

install.packages("ggplot2")
install.packages("dplyr")

renv automatically records each installation in renv.lock. No extra steps needed.

With your environment still active, run:

conda env export > environment.yml

This creates an environment.yml file in your current directory. Open it to see the full list of packages and versions that have been recorded.

For a cleaner file that only includes packages you explicitly installed (not their auto-installed dependencies):

conda env export --from-history > environment.yml

In the R console:

renv::snapshot()

This updates renv.lock to reflect your current package state. The file is already in your project folder — check that it’s been updated.