xsd_convert: Convert to XML Schema Definition (XSD) types

View source: R/xsd_convert.R

xsd_convertR Documentation

Convert to XML Schema Definition (XSD) types

Description

Convert the numeric, boolean and Date/time columns of a dataset xs:decimal, xsLboolean, xs:date and xs:dateTime.

Usage

xsd_convert(x, idcol, ...)

## S3 method for class 'data.frame'
xsd_convert(x, idcol = NULL, ...)

## S3 method for class 'dataset_df'
xsd_convert(x, idcol = "rowid", ...)

## S3 method for class 'tbl_df'
xsd_convert(x, idcol = NULL, ...)

## S3 method for class 'character'
xsd_convert(x, idcol = NULL, ...)

## S3 method for class 'numeric'
xsd_convert(x, idcol = NULL, ...)

## S3 method for class 'haven_labelled_defined'
xsd_convert(x, idcol = NULL, ...)

## S3 method for class 'integer'
xsd_convert(x, idcol = NULL, ...)

## S3 method for class 'logical'
xsd_convert(x, idcol = NULL, ...)

## S3 method for class 'factor'
xsd_convert(x, idcol = NULL, ...)

## S3 method for class 'POSIXct'
xsd_convert(x, idcol = NULL, ...)

## S3 method for class 'Date'
xsd_convert(x, idcol = NULL, ...)

## S3 method for class 'difftime'
xsd_convert(x, idcol = NULL, ...)

Arguments

x

An object to be coerced to an XLM Schema defined string format.

idcol

The name or position of the column that contains the row (observation) identifiers. If NULL, it will make a new idcol from row.names().

...

Further optional parameters for generic method.

Value

A character vector of RDF-compatible typed literals. Each element corresponds to an input value, serialized according to its type (e.g., xs:string, xs:integer, xs:dateTime). For data frames or tibbles, each row is converted into a set of RDF triples, with columns mapped to predicates.

Examples

# Convert data.frame to XML Schema Definition
xsd_convert(data.frame(a = 1:3, b = c("a", "b", "c")))
# Convert dataset to XML Schema Definition
xsd_convert(head(dataset_df(orange_df)))
# Convert characters:
xsd_convert(c("apple", " banana ", "cherry"))

# To handle whitespace:
xsd_convert(trimws(c("apple", " banana ", "cherry"), "both"))
# Convert integers or doubles, numbers:
xsd_convert(1:3)
# Convert logical values:
xsd_convert(TRUE)
xsd_convert(factor(c("apple", "banana", "cherry")))
xsd_convert(as.difftime(c(3600, 5400), units = "secs"))

dataset documentation built on June 8, 2025, 10:15 a.m.