There are also a lot of useful tools in metID.

library(metID)
#>                 _    _____  ___ 
#>  _ __ ___   ___| |_  \_   \/   \
#> | '_ ` _ \ / _ \ __|  / /\/ /\ /
#> | | | | | |  __/ |_/\/ /_/ /_// 
#> |_| |_| |_|\___|\__\____/___,'  
#> 
#> metID,
#> More information can be found at https://jaspershen.github.io/metID/
#> If you use metID in you publication, please cite this publication:
#> Metabolic reaction network-based recursive metabolite annotation for untargeted metabolomics.
#> Authors: Xiaotao Shen (shenxt1990@163.com)
#> Maintainer: Xiaotao Shen.
#> Version 0.4.1 (2020702)
library(tidyverse)
#> ── Attaching packages ──────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
#> ✓ ggplot2 3.3.2.9000     ✓ purrr   0.3.4     
#> ✓ tibble  3.0.1          ✓ dplyr   0.8.5     
#> ✓ tidyr   1.0.2          ✓ stringr 1.4.0     
#> ✓ readr   1.3.1          ✓ forcats 0.5.0
#> ── Conflicts ─────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag()    masks stats::lag()

Read MS2 data

Read msp format file using readMGF

result <- readMGF(file)

Read mzXML format file using readMZXML

result <- readMZXML(file, threads = 3)

Read MGF format file using readMGF

result <- readMGF(file)