|
1 | | -#' Field class |
| 1 | +#' @title Field class |
| 2 | +#' |
| 3 | +#' @description Class representing a field in the schema. |
| 4 | +#' |
| 5 | +#' Data values can be cast to native R types. Casting a value checks whether it is of the expected type, in the correct format, and compliant with any constraints imposed by the schema. |
| 6 | +#' |
| 7 | +#' @usage |
| 8 | +#' # Field$new(descriptor, missingValues = list("")) |
| 9 | +#' |
| 10 | +#' @param descriptor Schema field descriptor. |
| 11 | +#' @param missingValues A list with vector strings representing missing values. |
2 | 12 | #' |
3 | | -#' @description Class represents field in the schema. |
4 | | -#' |
5 | | -#' Data values can be cast to native R types. Casting a value will check |
6 | | -#' the value is of the expected type, is in the correct format, |
7 | | -#' and complies with any constraints imposed by a schema. |
8 | | -#' |
9 | | -#' @usage # Field$new(descriptor, missingValues = list("")) |
10 | | -#' @param descriptor Schema field descriptor |
11 | | -#' @param missingValues A list with vector strings representing missing values |
12 | | -#' |
13 | | -#' |
14 | 13 | #' @section Methods: |
15 | 14 | #' \describe{ |
16 | | -#' |
17 | | -#' \item{\code{Field$new(descriptor, missingValues = list(""))}}{ |
18 | | -#'Constructor to instantiate \code{Field} class.} |
19 | | -#' \itemize{ |
20 | | -#' \item{\code{descriptor }}{Schema field descriptor.} |
21 | | -#' \item{\code{missingValues }}{A list with vector strings representing missing values.} |
22 | | -#' \item{\code{TableSchemaError }}{Raises any error occured in the process.} |
23 | | -#' \item{\code{Field }}{Returns \code{Field} class instance.} |
24 | | -#' } |
25 | | -#' \item{\code{cast_value(value, constraints=TRUE)}}{ |
26 | | -#' Cast given value according to the field type and format.} |
27 | | -#' \itemize{ |
28 | | -#' \item{\code{value }}{Value to cast against field} |
29 | | -#' \item{\code{constraints }}{ Gets constraints configuration: |
30 | | -#' it could be set to true to disable constraint checks, or |
31 | | -#' it could be a List of constraints to check} |
32 | | -#' \item{\code{errors$TableSchemaError }}{Raises any error occured in the process} |
33 | | -#' \item{\code{any }}{Returns cast value} |
34 | | -#' } |
35 | | -#' |
36 | | -#' \item{\code{testValue(value, constraints=TRUE)}}{ |
37 | | -#' Test if value is compliant to the field.} |
38 | | -#' \itemize{ |
39 | | -#' \item{\code{value }}{Value to cast against field} |
40 | | -#' \item{\code{constraints }}{Constraints configuration} |
41 | | -#' \item{\code{Boolean }}{Returns if value is compliant to the field} |
42 | | -#' } |
| 15 | +#' \item{\code{Field$new(descriptor, missingValues = list(""))}}{Constructor to instantiate the \code{Field} class. Accepts the following arguments: |
| 16 | +#' \describe{ |
| 17 | +#' \item{\code{descriptor}}{Schema field descriptor.} |
| 18 | +#' \item{\code{missingValues}}{A list of strings representing missing values.} |
| 19 | +#' \item{\code{TableSchemaError}}{Raised if an error occurs during instantiation.} |
| 20 | +#' \item{\code{Field}}{Returns a \code{Field} class instance.} |
| 21 | +#' } |
| 22 | +#' } |
| 23 | +#' |
| 24 | +#' \item{\code{cast_value(value, constraints = TRUE)}}{Casts a given value according to the field's type and format. |
| 25 | +#' \describe{ |
| 26 | +#' \item{\code{value}}{Value to cast.} |
| 27 | +#' \item{\code{constraints}}{Logical or list of constraints to apply.} |
| 28 | +#' \item{\code{errors$TableSchemaError}}{Raised if casting fails due to a constraint violation.} |
| 29 | +#' \item{\code{any}}{Returns the cast value.} |
| 30 | +#' } |
| 31 | +#' } |
| 32 | +#' |
| 33 | +#' \item{\code{testValue(value, constraints = TRUE)}}{Tests if a value complies with the field definition. |
| 34 | +#' \describe{ |
| 35 | +#' \item{\code{value}}{Value to test.} |
| 36 | +#' \item{\code{constraints}}{Constraints configuration.} |
| 37 | +#' \item{\code{Boolean}}{Returns \code{TRUE} if the value is compliant.} |
| 38 | +#' } |
| 39 | +#' } |
43 | 40 | #' } |
44 | | -#' |
| 41 | +#' |
45 | 42 | #' @section Properties: |
46 | 43 | #' \describe{ |
47 | | -#' \item{\code{name}}{Returns field name} |
48 | | -#' \item{\code{type}}{Returns field type} |
49 | | -#' \item{\code{format}}{Returns field format} |
50 | | -#' \item{\code{required}}{Returns \code{TRUE} if field is required} |
51 | | -#' \item{\code{constraints}}{Returns list with field constraints} |
52 | | -#' \item{\code{descriptor}}{Returns field descriptor} |
| 44 | +#' \item{\code{name}}{Returns the field name.} |
| 45 | +#' \item{\code{type}}{Returns the field type.} |
| 46 | +#' \item{\code{format}}{Returns the field format.} |
| 47 | +#' \item{\code{required}}{Returns \code{TRUE} if the field is required.} |
| 48 | +#' \item{\code{constraints}}{Returns a list of field constraints.} |
| 49 | +#' \item{\code{descriptor}}{Returns the field descriptor.} |
53 | 50 | #' } |
54 | | -#' |
55 | | -#' |
56 | | -#' @details |
57 | | -#' A field descriptor \code{MUST} be a JSON object that describes a single field. |
58 | | -#' The descriptor provides additional human-readable documentation for a field, |
59 | | -#' as well as additional information that may be used to validate the field or |
60 | | -#' create a user interface for data entry. |
61 | | -#' |
62 | | -#' The field descriptor \code{object} \code{MAY} contain any number of other properties. |
63 | | -#' Some specific properties are defined below. Of these, only the \code{name} property is \code{REQUIRED}. |
64 | | -#' |
| 51 | +#' |
| 52 | +#' @details |
| 53 | +#' A field descriptor \code{MUST} be a JSON object that describes a single field. The descriptor provides both human-readable documentation and machine-readable validation rules. It may also guide user interface generation for data entry. |
| 54 | +#' |
| 55 | +#' The descriptor \code{object} \code{MAY} include additional custom properties. Of these, only the \code{name} property is \code{REQUIRED}. |
| 56 | +#' |
65 | 57 | #' \describe{ |
66 | | -#' \item{\code{name}}{ |
67 | | -#' The field descriptor \code{MUST} contain a \code{name} property. |
68 | | -#' This property \code{SHOULD} correspond to the name of field/column in the data file (if it has a name). |
69 | | -#' As such it \code{SHOULD} be unique (though it is possible, but very bad practice, for the data file to |
70 | | -#' have multiple columns with the same name). \code{name} \code{SHOULD NOT} be considered case sensitive in |
71 | | -#' determining uniqueness. However, since it should correspond to the name of the field in the data file |
72 | | -#' it may be important to preserve case.} |
73 | | -#' \item{\code{title}}{ |
74 | | -#' A human readable label or title for the field.} |
75 | | -#' |
76 | | -#' \item{\code{description}}{ |
77 | | -#' A description for this field e.g. "The recipient of the funds".} |
| 58 | +#' \item{\code{name}}{The descriptor \code{MUST} contain a \code{name} property, typically corresponding to the column name in the data file. This name \code{SHOULD} be unique, and while not case-sensitive for uniqueness, preserving case is advisable.} |
| 59 | +#' \item{\code{title}}{A human-readable label for the field.} |
| 60 | +#' \item{\code{description}}{A text description of the field, e.g., "The recipient of the funds".} |
78 | 61 | #' } |
79 | | -#' |
80 | | -#' |
81 | | -#' |
| 62 | +#' |
82 | 63 | #' @section Language: |
83 | | -#' The key words \code{MUST}, \code{MUST NOT}, \code{REQUIRED}, \code{SHALL}, \code{SHALL NOT}, |
84 | | -#' \code{SHOULD}, \code{SHOULD NOT}, \code{RECOMMENDED}, \code{MAY}, and \code{OPTIONAL} |
85 | | -#' in this package documents are to be interpreted as described in \href{https://www.ietf.org/rfc/rfc2119.txt}{RFC 2119}. |
86 | | -#' |
87 | | -#' |
| 64 | +#' The key words \code{MUST}, \code{MUST NOT}, \code{REQUIRED}, \code{SHALL}, \code{SHALL NOT}, \code{SHOULD}, \code{SHOULD NOT}, \code{RECOMMENDED}, \code{MAY}, and \code{OPTIONAL} in this documentation are to be interpreted as described in \href{https://www.ietf.org/rfc/rfc2119.txt}{RFC 2119}. |
| 65 | +#' |
88 | 66 | #' @docType class |
89 | 67 | #' @importFrom R6 R6Class |
90 | 68 | #' @export |
91 | 69 | #' @include types.R |
92 | 70 | #' @include constraints.R |
93 | 71 | #' @keywords data |
94 | | -#' @return Object of \code{\link{R6Class}} . |
| 72 | +#' @return Object of class \code{\link{R6Class}}. |
95 | 73 | #' @format \code{\link{R6Class}} object. |
96 | | -#' @param base_path see description |
97 | | -#' @param strict see description |
98 | | -#' @param value see description |
99 | | -#' @param constraints see description |
100 | | -#' @param ... see description |
| 74 | +#' |
101 | 75 | #' @seealso \href{https://specs.frictionlessdata.io//table-schema/#field-descriptors}{Field Descriptors Specifications} |
102 | | -#' |
103 | 76 | #' @examples |
104 | 77 | #' DESCRIPTOR = list(name = "height", type = "number") |
105 | 78 | #' |
|
0 commit comments