This short guide provides a quick overview of the core functions to
use the mwbenchr package to interact with mass spectrometry
and study data. For a complete tutorial, refer to the Getting
Started section of the documentation.
First, load the mwbenchr package:
Create a client to interact with the API:
client <- mw_rest_client()Fetch compound information by providing its PubChem CID. Here, we use
CID 5281365 as an example:
compound <- get_compound_by_pubchem_cid(client, 5281365)
print(compound)
#> # A tibble: 1 × 12
#> pubchem_cid regno formula exactmass inchi_key name sys_name lm_id kegg_id
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 5281365 28467 C20H34O 290.260966 OJISWRZIEWC… Gera… 3,7,11,… LMPR… C09094
#> # ℹ 3 more variables: chebi_id <chr>, metacyc_id <chr>, smiles <chr>Retrieve data from a study by providing its study ID (e.g.,
"ST000001"). Convert the response into a data frame:
study_data <- get_study_data(client, "ST000001")
study_df <- response_to_df(study_data)
head(study_df)
#> # A tibble: 6 × 8
#> study_id analysis_id analysis_summary metabolite_name metabolite_id
#> <chr> <chr> <chr> <chr> <chr>
#> 1 ST000001 AN000001 GCMS positive ion mode 1,2,4-benzenetriol ME000097
#> 2 ST000001 AN000001 GCMS positive ion mode 1,2,4-benzenetriol ME000097
#> 3 ST000001 AN000001 GCMS positive ion mode 1,2,4-benzenetriol ME000097
#> 4 ST000001 AN000001 GCMS positive ion mode 1,2,4-benzenetriol ME000097
#> 5 ST000001 AN000001 GCMS positive ion mode 1,2,4-benzenetriol ME000097
#> 6 ST000001 AN000001 GCMS positive ion mode 1,2,4-benzenetriol ME000097
#> # ℹ 3 more variables: refmet_name <chr>, units <chr>, DATA <named list>If you want to search for compounds based on their mass (optional):
Search for studies related to Diabetes in Human blood samples. The result is returned as a data frame:
diabetes_studies <- search_metstat(
client,
species = "Human",
sample_source = "Blood",
disease = "Diabetes"
)Convert the result to a data frame and view:
diabetes_df <- response_to_df(diabetes_studies)
head(diabetes_df)
#> # A tibble: 6 × 6
#> row_id study study_title species source disease
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Row1 ST003897 Postprandial Plasma Lipidomic Changes … Human Blood Diabet…
#> 2 Row2 ST003896 Postprandial Plasma Metabolomic Change… Human Blood Diabet…
#> 3 Row3 ST003895 Postprandial Plasma Metabolomic Change… Human Blood Diabet…
#> 4 Row4 ST003894 Postprandial Plasma Lipidomic Changes … Human Blood Diabet…
#> 5 Row5 ST003671 Discovery of Metabolic Biomarkers for … Human Blood Diabet…
#> 6 Row6 ST003636 Individual glycemic responses to carbo… Human Blood Diabet…Session Info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.5.1 (2025-06-13)
#> os Ubuntu 24.04.3 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language en
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2025-09-01
#> pandoc 3.1.11 @ /opt/hostedtoolcache/pandoc/3.1.11/x64/ (via rmarkdown)
#> quarto NA
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> bit 4.6.0 2025-03-06 [1] RSPM
#> bit64 4.6.0-1 2025-01-16 [1] RSPM
#> bslib 0.9.0 2025-01-30 [1] RSPM
#> cachem 1.1.0 2024-05-16 [1] RSPM
#> cli 3.6.5 2025-04-23 [1] RSPM
#> crayon 1.5.3 2024-06-20 [1] RSPM
#> curl 7.0.0 2025-08-19 [1] RSPM
#> desc 1.4.3 2023-12-10 [1] RSPM
#> digest 0.6.37 2024-08-19 [1] RSPM
#> dplyr 1.1.4 2023-11-17 [1] RSPM
#> evaluate 1.0.5 2025-08-27 [1] RSPM
#> farver 2.1.2 2024-05-13 [1] RSPM
#> fastmap 1.2.0 2024-05-15 [1] RSPM
#> fs 1.6.6 2025-04-12 [1] RSPM
#> generics 0.1.4 2025-05-09 [1] RSPM
#> ggplot2 3.5.2 2025-04-09 [1] RSPM
#> glue 1.8.0 2024-09-30 [1] RSPM
#> gtable 0.3.6 2024-10-25 [1] RSPM
#> htmltools 0.5.8.1 2024-04-04 [1] RSPM
#> httr2 1.2.1 2025-07-22 [1] RSPM
#> jquerylib 0.1.4 2021-04-26 [1] RSPM
#> jsonlite 2.0.0 2025-03-27 [1] RSPM
#> knitr 1.50 2025-03-16 [1] RSPM
#> lifecycle 1.0.4 2023-11-07 [1] RSPM
#> magrittr 2.0.3 2022-03-30 [1] RSPM
#> mwbenchr * 0.0.1 2025-09-01 [1] local
#> pillar 1.11.0 2025-07-04 [1] RSPM
#> pkgconfig 2.0.3 2019-09-22 [1] RSPM
#> pkgdown 2.1.3 2025-05-25 [1] any (@2.1.3)
#> purrr 1.1.0 2025-07-10 [1] RSPM
#> R6 2.6.1 2025-02-15 [1] RSPM
#> ragg 1.4.0 2025-04-10 [1] RSPM
#> rappdirs 0.3.3 2021-01-31 [1] RSPM
#> RColorBrewer 1.1-3 2022-04-03 [1] RSPM
#> rlang 1.1.6 2025-04-11 [1] RSPM
#> rmarkdown 2.29 2024-11-04 [1] RSPM
#> sass 0.4.10 2025-04-11 [1] RSPM
#> scales 1.4.0 2025-04-24 [1] RSPM
#> sessioninfo 1.2.3 2025-02-05 [1] any (@1.2.3)
#> systemfonts 1.2.3 2025-04-30 [1] RSPM
#> textshaping 1.0.1 2025-05-01 [1] RSPM
#> tibble 3.3.0 2025-06-08 [1] RSPM
#> tidyselect 1.2.1 2024-03-11 [1] RSPM
#> tzdb 0.5.0 2025-03-15 [1] RSPM
#> utf8 1.2.6 2025-06-08 [1] RSPM
#> vctrs 0.6.5 2023-12-01 [1] RSPM
#> vroom 1.6.5 2023-12-05 [1] RSPM
#> xfun 0.53 2025-08-19 [1] RSPM
#> yaml 2.3.10 2024-07-26 [1] RSPM
#>
#> [1] /home/runner/work/_temp/Library
#> [2] /opt/R/4.5.1/lib/R/site-library
#> [3] /opt/R/4.5.1/lib/R/library
#> * ── Packages attached to the search path.
#>
#> ──────────────────────────────────────────────────────────────────────────────Here, we covered just fundamental implemented methods in the
mwbenchr package, including how to interact with compound
and study data, as well as how to search for mass spectrometry-related
compounds and studies.
For more detailed examples and additional functions, please refer to the Getting Started of the package, which covers the full tutorial.
