#rfc-822 #lossless #parser #edit #r

r-description

Parsing and editor for R DESCRIPTION files

9 releases

0.3.3 Mar 28, 2025
0.3.1 Nov 3, 2024
0.2.2 Oct 9, 2024
0.1.2 Sep 25, 2024
0.1.0 Aug 28, 2024

#833 in Parser implementations

Download history 300/week @ 2024-12-24 481/week @ 2024-12-31 278/week @ 2025-01-07 235/week @ 2025-01-14 240/week @ 2025-01-21 270/week @ 2025-01-28 1248/week @ 2025-02-04 3802/week @ 2025-02-11 1126/week @ 2025-02-18 1463/week @ 2025-02-25 3827/week @ 2025-03-04 4454/week @ 2025-03-11 1688/week @ 2025-03-18 2041/week @ 2025-03-25 1229/week @ 2025-04-01 820/week @ 2025-04-08

6,819 downloads per month
Used in 2 crates

Apache-2.0

95KB
2K SLoC

R DESCRIPTION parser

This crate provides a parser and editor for the DESCRIPTION files used in R packages.

See https://r-pkgs.org/description.html and https://cran.r-project.org/doc/manuals/R-exts.html for more information on the format.

Besides parsing the control files it also supports parsing and comparison of version strings according to the R package versioning scheme as well as relations between versions.

Example


use std::str::FromStr;
use r_description::lossy::RDescription;

let mut desc = RDescription::from_str(r###"Package: foo
Version: 1.0
Depends: R (>= 3.0.0)
Description: A foo package
Title: A foo package
License: GPL-3
"###).unwrap();

assert_eq!(desc.name, "foo");
assert_eq!(desc.version, "1.0".parse().unwrap());
assert_eq!(desc.depends, Some("R (>= 3.0.0)".parse().unwrap()));

desc.license = "MIT".to_string();
use r_description::Version;

let v1: Version = "1.2.3-alpha".parse().unwrap();
let v2: Version = "1.2.3".parse().unwrap();
assert!(v1 < v2);

use std::str::FromStr;
use r_description::lossy::Relations;

let v1 = r_description::Version::from_str("1.2.3").unwrap();
let rels: Relations = "cli (>= 2.0), crayon (= 1.3.4), testthat".parse().unwrap();
assert_eq!(3, rels.len());
assert_eq!(rels[0].name, "cli");

Dependencies

~5.5–7.5MB
~125K SLoC