Duplicate Character Counter in R

Published on 06 May 2026 (Updated: 06 May 2026)

Welcome to the Duplicate Character Counter in R page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

args <- commandArgs(trailingOnly = TRUE)

USAGE <- "Usage: please provide a string"

if (length(args) != 1 || !nzchar(x <- args[[1]])) {
  cat(USAGE, "\n")
  quit(status = 1)
}

chars <- strsplit(x, "")[[1]]
chars <- chars[grepl("[[:alnum:]]", chars)]

if (!length(chars)) {
  cat("No duplicate characters\n")
  quit(status = 0)
}

counts <- table(chars)

dups <- counts[counts > 1]
dups <- dups[order(match(names(dups), chars))]

if (!length(dups)) {
  cat("No duplicate characters\n")
} else {
  cat(paste(names(dups), dups, sep = ": "), sep = "\n")
}

Duplicate Character Counter in R was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.