Learn R Programming

ambiorix (version 2.2.0)

as_path_to_pattern: Path to pattern

Description

Identify a function as a path to pattern function; a function that accepts a path and returns a matching pattern.

Usage

as_path_to_pattern(path)

Value

Object of class "pathToPattern".

Arguments

path

A function that accepts a character vector of length 1 and returns another character vector of length 1.

Examples

Run this code
fn <- function(path) {
  pattern <- gsub(":([^/]+)", "(\\\\w+)", path)
  paste0("^", pattern, "$")
}

path_to_pattern <- as_path_to_pattern(fn)

path <- "/dashboard/profile/:user_id"
pattern <- path_to_pattern(path) # "^/dashboard/profile/(\w+)$"

Run the code above in your browser using DataLab