comsub: Find the longest common starting substring or directory

View source: R/comsub.R

comsubR Documentation

Find the longest common starting substring or directory

Description

The function search for the longest common prefix between multiple strings.

Usage

comsub(data, sep = "")

Arguments

data

A vector of strings

sep

A character which is used to separate elements; default ("") is used to compare single characters; other useful alternatives are "/" (or "\\\\" in Windows) to find the longest common directory, or " " to compare words instead of characters.

Value

A character with the longest common initial substring

Note

Modified from a suggestion taken from stackoverflow.

Author(s)

Luigi Ranghetti, phD (2019)

References

L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020). "sen2r": An R toolbox for automatically downloading and preprocessing Sentinel-2 satellite data. Computers & Geosciences, 139, 104473. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.cageo.2020.104473")}, URL: https://sen2r.ranghetti.info/.

Examples

strings <- c("/home/user/git/sen2r",
             "/home/user/git_data/sen2r/ex/vrt/01_translate/")

comsub(strings)

comsub(strings, sep="/")

sen2r documentation built on Nov. 10, 2023, 9:08 a.m.