as_path_to_pattern: Path to pattern

View source: R/route.R

as_path_to_patternR Documentation

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)

Arguments

path

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

Value

Object of class "pathToPattern".

Examples

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+)$"


ambiorix documentation built on April 3, 2025, 9:34 p.m.