Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 10 min read

Humanize Writer Palmyra Output in R: A DESCRIPTION File Description Linter + 5 Free Tools (2026)

Disclosure: I'm on the UnAIMyText team; you'll find it in third place in the closing tool list. Nothing in this R script calls our product. Every R package carries a DESCRIPTION file, and two of its fields get read by f

Disclosure: I'm on the UnAIMyText team; you'll find it in third place in the closing tool list. Nothing in this R script calls our product.

Every R package carries a DESCRIPTION file, and two of its fields get read by far more people than the code: Title and Description. They're what shows up in package listings and on every page that displays package metadata. They're also the two fields people now hand to a chat model. A made-up example, built from patterns I keep seeing in pull requests:

Package: rotaplan
Title: rotaplan: a Robust and Comprehensive Toolkit for Planning Holiday Shift Rotations.
Version: 0.1.0
Authors@R: person("Mira", "Kowal", email = "[email protected]", role = c("aut", "cre"))
License: MIT + file LICENSE
Encoding: UTF-8
Description: rotaplan is a powerful, seamless and blazing-fast package that
    empowers small teams to effortlessly plan holiday shift rotations!
    .
    It leverages cutting-edge scheduling to unlock fairness.

So I wrote rdesc, a 86-line R script that reads DESCRIPTION, checks Title and Description against the rules in the R manual plus a few habits of mine, and can optionally ask a Palmyra model on Writer for a plainer paragraph.

The rules come from Writing R Extensions

The section on the DESCRIPTION file in Writing R Extensions is unusually specific about these two fields. For Title: it should be a short description of the package, some listings may cut it at 65 characters, it should be in title case (the manual points to tools::toTitleCase), it shouldn't end in a period, and it shouldn't repeat the package name, since the name usually gets printed right before it. For Description: several complete sentences are fine, but only one paragraph, and the manual calls it good practice not to open with the package name or "This package".

The format is a Debian control file, the manual says, which read.dcf() parses; continuation lines start with a space or a tab. So base R already ships the parser.

What it flags

  • title long: over 65 characters.
  • title period: a final . (an ellipsis is left alone).
  • title case: the title differs from what tools::toTitleCase() returns.
  • title repeats name: the title begins with the package name.
  • paragraphs: a blank line inside Description.
  • opener: the description starts with the package name, or with "This package", "The package", "A package", "An R package".
  • buzzwords: fifteen words from my own list ("seamless", "leverage", "empower"...). A trailing "s" still counts, so "empowers" and "leverages" match.
  • exclamation: any ! in the description.

Exit status: 0 clean, 1 something to fix, 2 when rdesc itself couldn't finish (unreadable file, no Description, no key, HTTP error).

The script

#!/usr/bin/env Rscript
# rdesc: lint the Title and Description fields of an R package DESCRIPTION file.
# Usage: Rscript rdesc.R [pkgdir|DESCRIPTION] [--rewrite]
args <- commandArgs(trailingOnly = TRUE)
rewrite <- "--rewrite" %in% args
args <- setdiff(args, "--rewrite")
path <- if (length(args)) args[[1]] else "."
if (dir.exists(path)) path <- file.path(path, "DESCRIPTION")

TITLE_MAX <- 65
BUZZ <- c("seamless", "seamlessly", "robust", "powerful", "cutting-edge", "effortless",
          "effortlessly", "comprehensive", "leverage", "unlock", "empower",
          "revolutionize", "blazing-fast", "game-changing", "streamline")

die <- function(msg) { message("rdesc: ", msg); quit(status = 2) }
one_line <- function(x) trimws(gsub("[[:space:]]+", " ", x))

lint <- function(pkg, title, desc) {
  out <- character()
  add <- function(rule, detail) out <<- c(out, sprintf("%s: %s: %s", pkg, rule, detail))
  if (!is.na(title)) {
    t1 <- one_line(title)
    if (nchar(t1) > TITLE_MAX) add("title long", sprintf("%d chars (listings may cut at %d)", nchar(t1), TITLE_MAX))
    if (grepl("\\.$", t1) && !grepl("\\.\\.\\.$", t1)) add("title period", "drop the final '.'")
    tc <- tools::toTitleCase(t1)
    if (!identical(tc, t1)) add("title case", sprintf("toTitleCase gives '%s'", tc))
    if (startsWith(tolower(t1), tolower(pkg))) add("title repeats name", "listings already show the name")
  }
  if (!is.na(desc)) {
    if (grepl("\n[[:space:]]*\n", desc)) add("paragraphs", "more than one; R-exts asks for one")
    d1 <- one_line(desc)
    if (startsWith(tolower(d1), tolower(pkg))) add("opener", sprintf("starts with '%s'", pkg))
    else if (grepl("^(this|the|an?) (r )?package", tolower(d1))) add("opener", sprintf("starts with '%s'", sub("^((\\S+ ){1,2}package).*", "\\1", d1)))
    words <- tolower(strsplit(d1, "[^A-Za-z0-9-]+")[[1]])
    hits <- BUZZ[BUZZ %in% words | paste0(BUZZ, "s") %in% words]
    if (length(hits)) add("buzzwords", paste(hits, collapse = ", "))
    if (grepl("!", d1, fixed = TRUE)) add("exclamation", "remove the '!'")
  }
  out
}

ask_writer <- function(pkg, title, desc) {
  key <- Sys.getenv("WRITER_API_KEY")
  if (key == "") die("set WRITER_API_KEY to use --rewrite")
  base <- sub("/+$", "", Sys.getenv("WRITER_BASE_URL", "https://api.writer.com/v1"))
  body <- list(model = Sys.getenv("WRITER_MODEL", "palmyra-x6"), max_tokens = 200,
               temperature = 0.3,
               messages = list(
                 list(role = "system", content = paste(
                   "You rewrite R package Description fields. Reply with one plain paragraph,",
                   "two sentences at most, no marketing words, and do not start with the package name.")),
                 list(role = "user", content = sprintf("Package: %s\nTitle: %s\nDescription: %s",
                                                       pkg, one_line(title), one_line(desc)))))
  h <- curl::new_handle()
  curl::handle_setheaders(h, Authorization = paste("Bearer", key), `Content-Type` = "application/json")
  curl::handle_setopt(h, postfields = jsonlite::toJSON(body, auto_unbox = TRUE))
  res <- tryCatch(curl::curl_fetch_memory(paste0(base, "/chat"), handle = h),
                  error = function(e) die(conditionMessage(e)))
  txt <- rawToChar(res$content)
  j <- tryCatch(jsonlite::fromJSON(txt, simplifyVector = FALSE), error = function(e) NULL)
  if (res$status_code != 200) {
    why <- if (!is.null(j$errors)) j$errors[[1]]$description else "no JSON body"
    die(sprintf("HTTP %d from Writer (%s)", res$status_code, why))
  }
  if (is.null(j)) die("Writer returned something that isn't JSON")
  one_line(j$choices[[1]]$message$content)
}

if (path == "-") path <- file("stdin")
fields <- tryCatch(read.dcf(path, fields = c("Package", "Title", "Description")),
                   error = function(e) die(paste("can't read DESCRIPTION:", conditionMessage(e))))
fields <- fields[1, ]  # a named vector; unname below, or identical() never matches
pkg <- unname(fields["Package"]); title <- unname(fields["Title"]); desc <- unname(fields["Description"])
if (is.na(pkg)) die("no Package field")
if (is.na(desc)) die(sprintf("%s has no Description field (R CMD check stops on this too)", pkg))

problems <- lint(pkg, title, desc)
if (!length(problems)) { cat(sprintf("ok: %s\n", one_line(desc))); quit(status = 0) }
cat(problems, sep = "\n")
if (rewrite) {
  s <- ask_writer(pkg, title, desc)
  cat(sprintf("suggested: %s\n", s))
  again <- lint(pkg, NA, s)
  if (length(again)) cat(paste("still:", again), sep = "\n")
}
quit(status = 1)

Two things I learned. A . continuation line is how a control file spells an empty line, and read.dcf() turns it into a real blank line in the returned string, so searching for \n followed by whitespace and another \n catches a second paragraph. Also, my first version flagged title case on a title that was already correct. read.dcf() returns a named character vector, toTitleCase() returns an unnamed one, and identical() compares the names too. Hence the unname() calls.

Install and run:

# Debian/Ubuntu: apt install r-base-core r-cran-curl r-cran-jsonlite
Rscript rdesc.R path/to/rotaplan
Rscript rdesc.R path/to/rotaplan --rewrite     # needs WRITER_API_KEY
Rscript rdesc.R - < DESCRIPTION

Output

On the sample package above (exit status 1):

rotaplan: title long: 82 chars (listings may cut at 65)
rotaplan: title period: drop the final '.'
rotaplan: title case: toTitleCase gives 'Rotaplan: a Robust and Comprehensive Toolkit for Planning Holiday Shift Rotations.'
rotaplan: title repeats name: listings already show the name
rotaplan: paragraphs: more than one; R-exts asks for one
rotaplan: opener: starts with 'rotaplan'
rotaplan: buzzwords: seamless, powerful, cutting-edge, effortlessly, leverage, unlock, empower, blazing-fast
rotaplan: exclamation: remove the '!'

Every rule fires there by design. A description that opens with "This package" and is otherwise fine:

snowroute: opener: starts with 'This package'

A lowercase title. The package is called cocoa and the word appears in the middle of the title, which is fine, so only the case rule fires:

cocoa: title case: toTitleCase gives 'Track Hot Cocoa Orders for a Holiday Stand'

And a DESCRIPTION with no Description field at all:

rdesc: nodesc has no Description field (R CMD check stops on this too)

That message isn't a guess. I built the same package with R CMD build, which produced nodesc_0.1.0.tar.gz without complaint, and then ran R CMD check on the tarball, which stopped at the check for the DESCRIPTION file:

* checking for file β€˜nodesc/DESCRIPTION’ ... ERROR
Required field missing or empty:
  β€˜Description’

Build won't catch it; check will.

The Writer call

Writer's chat completion reference documents POST https://api.writer.com/v1/chat: bearer token, required model, and a messages array with at least one entry. Optional fields include max_tokens and temperature (default 1). The reply text sits in choices[[1]]$message$content.

The reference examples use palmyra-x5, but the same page carries a deprecation notice: Palmyra X4 and X5 are deprecated on December 14, 2026, with Palmyra X6 as the migration path. Writer's models overview lists palmyra-x6 as available through the API, with a 1M-token context window and up to 8,192 output tokens. So rdesc defaults to palmyra-x6; WRITER_MODEL overrides it and WRITER_BASE_URL redirects to a mock or proxy. It sends max_tokens 200 and temperature 0.3.

Errors aren't shaped like the usual {"error": {...}} object. With a made-up key, the real endpoint returned HTTP 401 and a body with an errors array, each entry carrying a description ("Invalid API key"; with no header at all it says "No API key passed in"). rdesc prints that description:

rdesc: HTTP 401 from Writer (Invalid API key)

What was tested, and against what

I don't have a paid Writer key, so to be exact: the API side ran against a small Python mock of /v1/chat, plus real requests to Writer with a fake key. A bash script runs 23 checks, all passing on R 4.5.0 with curl 6.2.1 and jsonlite 1.9.1 on Debian Linux:

  • each rule fires on its own sample package, a lowercase title with the package name in the middle only trips the case rule, and a clean package prints ok: with its continuation lines joined and exits 0;
  • no argument uses the current folder, a DESCRIPTION path works directly, and - reads from stdin;
  • a missing file, a missing Description field, or --rewrite with no WRITER_API_KEY all exit 2;
  • the mock gets the request on /v1/chat (even with a trailing slash in WRITER_BASE_URL), with the bearer header, JSON, palmyra-x6, a 200-token cap, and system and user roles, the user text beginning Package: rotaplan; WRITER_MODEL swaps the model;
  • the canned reply is trimmed, put on one line and re-linted; mocked 401 and HTML-only 502 responses each produce a one-line error and status 2.

With the mock running, --rewrite appends:

suggested: Builds holiday shift rotations for small teams from a CSV of names and days off, and spreads the busiest dates evenly.

That's the mock's fixed reply, not Palmyra output.

Five free tools for the prose a linter can't judge

Character counts and word lists only go so far. No script can tell you whether the README or the vignette intro sounds like someone who actually uses the package wrote it. For that:

  1. R CMD check: not a writing tool, but run it in the same CI job; it's what catches a missing or empty mandatory field, as shown above.
  2. LanguageTool: free grammar and spelling checks that mostly leave function names alone.
  3. UnAIMyText: costs nothing, needs no account, and takes 500 words at a time in Standard mode. Paste the README paragraphs a generator wrote, and the "powerful and seamless" coating tends to come off. Then confirm that every function name, argument and version number made it through untouched.
  4. Hemingway Editor: points at long sentences in a vignette introduction; ignore what it thinks of read.dcf().
  5. Vale: configurable style rules for a docs folder; it reports and leaves the rewriting to you.

FAQ

What's a good free AI humanizer for R package docs?
For Title and Description, rdesc and a minute of your own editing are enough. When the README or vignette opening reads machine-made, I'd run it through UnAIMyText first, then LanguageTool.

Why not just use regular expressions on the file?
Continuation lines and the . convention make that fragile; read.dcf() is R's own parser for the format.

Will it work with another chat API?
Only if that API takes the same body at a /chat path and returns choices[[1]]$message$content. I tested the Writer shape and nothing else, and the error parsing expects Writer's errors[[1]]$description.

Verdict

Check Title and Description mechanically against Writing R Extensions, let Palmyra propose a paragraph if you're out of ideas, and write the last version into DESCRIPTION yourself. For the longer README and vignette prose, my free AI humanizer of choice is UnAIMyText: it removes the generated gloss without moving your function names, provided you proofread before pushing.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.