@@ -232,90 +232,7 @@ setMethod(f = "show",
232
232
)
233
233
234
234
235
- # ' @rdname as.code
236
- # ' @export
237
- # ' @examples
238
- # ' M = example_model()
239
- # ' as.code(M)
240
- # ' @return a string of code to reproduce the model
241
- setMethod (f = 'as.code ',
242
- signature = c(' model' ),
243
- definition = function (M ,start = ' M = ' ,mode = ' compact' ) {
244
- .as_code(M ,start ,mode )
245
- }
246
- )
247
-
248
-
249
235
250
- .as_code = function (M ,start = ' M = ' ,mode = ' compact' ) {
251
-
252
- if (! (mode %in% c(' compact' ,' neat' ,' expanded' ,' full' ))) {
253
- stop(paste0(' unknown option "' , mode , ' " for as.code()' ))
254
- }
255
- str = start
256
- # model object name
257
- str = paste0(str ,class(M )[1 ],' (' )
258
-
259
- # parameters
260
- P = param_ids(M )
261
-
262
- # add seq_in if not equal to data
263
- if (is(M ,' model' )) {
264
- if (M @ seq_in != ' data' | mode == ' full' ) {
265
- P = c(P ,' seq_in' )
266
- }
267
- }
268
- # add predicted if its not the default
269
- if (is(M ,' model' )) {
270
- N = new_struct(class(M )[1 ])
271
- if (length(predicted_name(N ))== 0 ) {
272
- N @ predicted = ' cake'
273
- }
274
-
275
- if (predicted_name(N ) != predicted_name(M ) | mode == ' full' ) {
276
- P = c(P ,' predicted' )
277
- }
278
- }
279
-
280
- if (mode != " compact" ) {
281
- str = paste0(str ,' \n ' )
282
- indent = nchar(start )+ 2
283
- } else {
284
- indent = (nchar(start )+ 1 )+ nchar(class(M )[1 ])
285
- }
286
-
287
- for (p in seq_len(length(P ))) {
288
- if (p > 1 | mode != " compact" ) {
289
- str = paste0(str ,paste0(rep(' ' ,indent ),collapse = ' ' ))
290
- }
291
-
292
- if (P [p ]== ' seq_in' ) {
293
- str = paste0(str ,P [p ], ' = "' , seq_in(M ), ' "' )
294
- } else if (P [p ]== ' predicted' ) {
295
- str = paste0(str ,P [p ], ' = "' , predicted_name(M ), ' "' )
296
- } else if (is(param_value(M ,P [p ]),' character' )) {
297
- str = paste0(str ,P [p ], ' = "' , as.character(param_value(M ,P [p ])), ' "' )
298
- } else {
299
- str = paste0(str ,P [p ], ' = ' , as.character(param_value(M ,P [p ])))
300
- }
301
-
302
-
303
- if (p == length(P )) {
304
- if (mode == ' expanded' ) {
305
- str = paste0(str ,' \n ' ,paste0(rep(' ' ,indent - 2 ),collapse = ' ' ))
306
- }
307
-
308
-
309
- str = paste0(str ,' )' )
310
-
311
-
312
- } else {
313
- str = paste0(str ,' ,\n ' )
314
- }
315
- }
316
-
317
- return (str )
318
- }
319
236
320
237
# autocompletion, return sample_meta column names
321
238
# ' @export
0 commit comments