Running QIIME 2 tutorials via R .

Hi all,

I am trying to work through the the CMI Tutorial, and run QIIME 2 via the proposed R commands.

However, I am unable to get past the first step. I've not been able to find any tutorials that explicitly discuss how this would work... So, here is what I've tried:

I activated my environment and then ran R:

(base)$ conda activate qiime2-amplicon-2025.4

(qiime2-amplicon-2025.4)$  R

R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(reticulate)
> Metadata <- import("qiime2")$Metadata
Error in py_module_import(module, convert = convert) : 
  ModuleNotFoundError: No module named 'qiime2'
Run `reticulate::py_last_error()` for details.

What is the preferred way to run QIIME 2 via R? Are there other commands or packages I need to load, install, or fix?

Looks like this is an old issue with reticulate

Try telling it exactly what conda env to use, even if you are using R within the correct conda env already

# Before loading library(reticulate) or as the very first reticulate command
reticulate::use_condaenv("qiime2-amplicon-2025.4", required = TRUE)
library(reticulate)

# then
qiime2 <- import("qiime2")
Metadata <- qiime2$Metadata
1 Like

Thanks @colinbrislawn! That worked!

But wow... that is quite an important missing step!

There are some other R command errors too... I assume the R-based tutorials are still being tweaked...

Apparently this is fixed in reticulate v1.31 and the amplicon env yaml file claims 1.36 so I'm not sure what's going on.

1 Like

Oh that part I was having issue with works now thanks to your help... I am referring to later steps in the tutorial... like this step, e.g. zipfile <- import("zipfile"). I get an error stating how I should specify 'QIIME' or other method... nothing seems to work.

I do not have an immediate need for this R functionality to work. It's just that some of my colleagues here like to use R, and was hoping to show them how they can to use QIIME 2 via R...

Hello @SoilRotifer,

Could you post the full error you get? We certainly want the R api to work for people.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.