ct_convert_unit: Convert values between different units

View source: R/ct_convert_unit.R

ct_convert_unitR Documentation

Convert values between different units

Description

Convert a numeric value from one unit to another. It supports area, distance (length), and angle units.

Usage

ct_convert_unit(x, from, to, show_units = FALSE)

Arguments

x

Numeric. Value(s) to convert.

from

Character. The unit to convert from. Can be any synonym e.g. "meter", "m", "metre", "feet", "^\circ", "um" (i.e \mu m), etc.

to

Character. The unit to convert to. Can also be any synonym.

show_units

Logical. If TRUE, returns the full table of supported units and their synonyms instead of performing a conversion.

Value

A numeric vector of converted values.

See Also

units_table() for supported units and synonyms.

Examples

# Distance
ct_convert_unit(1000, "m", "km")
ct_convert_unit(1, "mile", "m")
ct_convert_unit(12, "inches", "ft")

# Area
ct_convert_unit(1, "acre", "m2")
ct_convert_unit(2, "km2", "hectare")

# Angle
ct_convert_unit(180, "deg", "rad")
ct_convert_unit(pi, "rad", "deg")


ct documentation built on Oct. 22, 2026, 1:07 a.m.