@@ -25,15 +25,19 @@ DoubleMLData = R6Class("DoubleMLData",
2525 # ' @field all_variables (`character()`)\cr
2626 # ' All variables available in the dataset.
2727 all_variables = function (value ) {
28- if (missing(value )) return (names(self $ data ))
29- else stop(" can't set field all_variables" )
28+ if (missing(value )) {
29+ return (names(self $ data ))
30+ } else {
31+ stop(" can't set field all_variables" )
32+ }
3033 },
3134
3235 # ' @field d_cols (`character()`)\cr
3336 # ' The treatment variable(s).
3437 d_cols = function (value ) {
35- if (missing(value )) return (private $ d_cols_ )
36- else {
38+ if (missing(value )) {
39+ return (private $ d_cols_ )
40+ } else {
3741 d_cols = value # to get more meaningful assert error messages
3842 reset_value = ! is.null(self $ data_model )
3943 assert_character(d_cols , unique = TRUE )
@@ -49,37 +53,52 @@ DoubleMLData = R6Class("DoubleMLData",
4953 # ' @field data ([`data.table`][data.table::data.table()])\cr
5054 # ' Data object.
5155 data = function (value ) {
52- if (missing(value )) return (private $ data_ )
53- else stop(" can't set field data" )
56+ if (missing(value )) {
57+ return (private $ data_ )
58+ } else {
59+ stop(" can't set field data" )
60+ }
5461 },
5562
5663 # ' @field data_model ([`data.table`][data.table::data.table()])\cr
5764 # ' Internal data object that implements the causal model as specified by
5865 # ' the user via `y_col`, `d_cols`, `x_cols` and `z_cols`.
5966 data_model = function (value ) {
60- if (missing(value )) return (private $ data_model_ )
61- else stop(" can't set field data_model" )
67+ if (missing(value )) {
68+ return (private $ data_model_ )
69+ } else {
70+ stop(" can't set field data_model" )
71+ }
6272 },
6373
6474 # ' @field n_instr (`NULL`, `integer(1)`) \cr
6575 # ' The number of instruments.
6676 n_instr = function (value ) {
67- if (missing(value )) return (length(self $ z_cols ))
68- else stop(" can't set field n_instr" )
77+ if (missing(value )) {
78+ return (length(self $ z_cols ))
79+ } else {
80+ stop(" can't set field n_instr" )
81+ }
6982 },
7083
7184 # ' @field n_obs (`integer(1)`) \cr
7285 # ' The number of observations.
7386 n_obs = function (value ) {
74- if (missing(value )) return (dim(self $ data )[1 ])
75- else stop(" can't set field n_obs" )
87+ if (missing(value )) {
88+ return (dim(self $ data )[1 ])
89+ } else {
90+ stop(" can't set field n_obs" )
91+ }
7692 },
7793
7894 # ' @field n_treat (`integer(1)`) \cr
7995 # ' The umber of treatment variables.
8096 n_treat = function (value ) {
81- if (missing(value )) return (length(self $ d_cols ))
82- else stop(" can't set field n_treat" )
97+ if (missing(value )) {
98+ return (length(self $ d_cols ))
99+ } else {
100+ stop(" can't set field n_treat" )
101+ }
83102 },
84103
85104 # ' @field other_treat_cols (`NULL`, `character()`) \cr
@@ -89,23 +108,30 @@ DoubleMLData = R6Class("DoubleMLData",
89108 # ' the fitting stage. If `use_other_treat_as_covariate` is `FALSE`,
90109 # ' `other_treat_cols` is `NULL`.
91110 other_treat_cols = function (value ) {
92- if (missing(value )) return (private $ other_treat_cols_ )
93- else stop(" can't set field other_treat_cols" )
111+ if (missing(value )) {
112+ return (private $ other_treat_cols_ )
113+ } else {
114+ stop(" can't set field other_treat_cols" )
115+ }
94116 },
95117
96118 # ' @field treat_col (`character(1)`) \cr
97119 # ' "Active" treatment variable in the multiple-treatment case.
98120 treat_col = function (value ) {
99- if (missing(value )) return (private $ treat_col_ )
100- else stop(" can't set field treat_col" )
121+ if (missing(value )) {
122+ return (private $ treat_col_ )
123+ } else {
124+ stop(" can't set field treat_col" )
125+ }
101126 },
102127
103128 # ' @field use_other_treat_as_covariate (`logical(1)`) \cr
104129 # ' Indicates whether in the multiple-treatment case the other treatment
105130 # ' variables should be added as covariates. Default is `TRUE`.
106131 use_other_treat_as_covariate = function (value ) {
107- if (missing(value )) return (private $ use_other_treat_as_covariate_ )
108- else {
132+ if (missing(value )) {
133+ return (private $ use_other_treat_as_covariate_ )
134+ } else {
109135 use_other_treat_as_covariate = value # to get more meaningful assert error messages
110136 reset_value = ! is.null(self $ data_model )
111137 assert_logical(use_other_treat_as_covariate , len = 1 )
@@ -123,8 +149,9 @@ DoubleMLData = R6Class("DoubleMLData",
123149 # ' `d_cols`, nor as instrumental variables `z_cols` are used as covariates.
124150 # ' Default is `NULL`.
125151 x_cols = function (value ) {
126- if (missing(value )) return (private $ x_cols_ )
127- else {
152+ if (missing(value )) {
153+ return (private $ x_cols_ )
154+ } else {
128155 x_cols = value # to get more meaningful assert error messages
129156 reset_value = ! is.null(self $ data_model )
130157 if (! is.null(x_cols )) {
@@ -153,8 +180,9 @@ DoubleMLData = R6Class("DoubleMLData",
153180 # ' @field y_col (`character(1)`) \cr
154181 # ' The outcome variable.
155182 y_col = function (value ) {
156- if (missing(value )) return (private $ y_col_ )
157- else {
183+ if (missing(value )) {
184+ return (private $ y_col_ )
185+ } else {
158186 y_col = value # to get more meaningful assert error messages
159187 reset_value = ! is.null(self $ data_model )
160188 assert_character(y_col , len = 1 )
@@ -170,8 +198,9 @@ DoubleMLData = R6Class("DoubleMLData",
170198 # ' @field z_cols (`NULL`, `character()`) \cr
171199 # ' The instrumental variables. Default is `NULL`.
172200 z_cols = function (value ) {
173- if (missing(value )) return (private $ z_cols_ )
174- else {
201+ if (missing(value )) {
202+ return (private $ z_cols_ )
203+ } else {
175204 z_cols = value # to get more meaningful assert error messages
176205 reset_value = ! is.null(self $ data_model )
177206 if (! is.null(z_cols )) {
@@ -239,7 +268,7 @@ DoubleMLData = R6Class("DoubleMLData",
239268
240269 invisible (self )
241270 },
242-
271+
243272 # ' @description
244273 # ' Print DoubleMLData objects.
245274 print = function () {
@@ -252,10 +281,10 @@ DoubleMLData = R6Class("DoubleMLData",
252281 " Instrument(s): " , paste0(self $ z_cols , collapse = " , " ), " \n " ,
253282 " No. Observations: " , self $ n_obs , " \n " )
254283 cat(header , " \n " ,
255- " \n ------------------ Data summary ------------------\n " ,
256- data_info ,
257- sep = " " )
258-
284+ " \n ------------------ Data summary ------------------\n " ,
285+ data_info ,
286+ sep = " " )
287+
259288 invisible (self )
260289 },
261290
@@ -395,9 +424,9 @@ double_ml_data_from_data_frame = function(df, x_cols = NULL, y_col = NULL,
395424 d_cols = NULL , z_cols = NULL ,
396425 use_other_treat_as_covariate = TRUE ) {
397426 data = DoubleMLData $ new(df ,
398- x_cols = x_cols , y_col = y_col , d_cols = d_cols ,
399- z_cols = z_cols ,
400- use_other_treat_as_covariate = use_other_treat_as_covariate )
427+ x_cols = x_cols , y_col = y_col , d_cols = d_cols ,
428+ z_cols = z_cols ,
429+ use_other_treat_as_covariate = use_other_treat_as_covariate )
401430 return (data )
402431}
403432
0 commit comments