@@ -17,14 +17,16 @@ Data2fd <- function(argvals=NULL, y=NULL, basisobj=NULL, nderiv=NULL,
17
17
18
18
# another rest with messages
19
19
20
+ argChk <- argvalsySwap(argvals , y , basisobj )
21
+
20
22
if (! is.numeric(AV <- argChk $ argvals )){
21
- # terminal message
22
- if (is.null(AV )) stop( ' is.null(argChk$argvals); should be numeric ' )
23
- # . otherwise alert message
23
+ print( AV )
24
+ if (is.null(AV ))
25
+ stop( ' is.null(argChk$argvals); should be numeric ' )
24
26
cat(' argChk$argvals is not numeric.\n ' )
25
27
cat(' class(argChk$argvals) = ' , class(AV ), ' \n ' )
26
28
print(AV )
27
- }
29
+ }
28
30
29
31
# . Success and smoothing ... S3 object of class fdSmooth is returned
30
32
@@ -46,7 +48,7 @@ argvalsySwap = function(argvals=NULL, y=NULL, basisobj=NULL) {
46
48
if (inherits(basisobj , ' basisfd' )) rangeval <- basisobj $ rangeval
47
49
48
50
# #. --------------------------------------------------------------------------
49
- # # 1. if(is.null(y)) use argvals
51
+ # # 1. if(is.null(y)) use argvals for y
50
52
# #. --------------------------------------------------------------------------
51
53
52
54
if (is.null(y )){
@@ -58,44 +60,49 @@ argvalsySwap = function(argvals=NULL, y=NULL, basisobj=NULL) {
58
60
}
59
61
60
62
# #. --------------------------------------------------------------------------
61
- # # 2. if(is.null(argvals)). argvals <- seq(basisobj$rangeval, dim(y)[1])
63
+ # # 2. test for missing argvals, if so construct a sequence
62
64
# #. --------------------------------------------------------------------------
63
65
64
66
dimy <- dim(as.array(y ))
65
- if (is.null(argvals )){
66
- {
67
+ if (is.null(argvals )) {
68
+ # the following code block is run if TRUE
69
+ { # beginning of code block
67
70
if (is.null(basisobj )){
68
71
basisobj <- create.bspline.basis(basisobj )
69
72
} else {
70
73
if (is.numeric(basisobj )) {
71
74
if (length(basisobj )> 1 ){
72
75
basisobj <- create.bspline.basis(basisobj )
73
- } else
76
+ } else
74
77
basisobj <- create.bspline.basis(norder = basisobj )
75
78
}
76
79
else {
77
80
if (inherits(basisobj , ' fd' )){
78
81
basisobj <- basisobj $ basis
79
- } else
82
+ } else
80
83
if (inherits(basisobj , ' fdPar' ))
81
84
basisobj <- basisobj $ fd $ basis
82
85
}
83
86
}
84
- }
85
- if (is.null(rangeval ))
86
- stop(' basisobj does not have a required ' ,
87
- ' rangeval component.' )
88
- #
87
+ } # . end of code block
88
+ # This is executed whether or not the previous was
89
+ # . locate the range from basisobj
90
+ a01 <- basisobj $ rangeval
91
+ # if range is null, error message and stop
92
+ if (is.null(a01 ))
93
+ stop(' basisobj does not have a required rangeval component.' )
89
94
n <- dimy [1 ]
90
- # . alert message
91
- cat(paste(" 'argvals' is missing; using seq(" , rangeval [1 ],
92
- " , " , rangeval [2 ], " , length=" , n , " )\n " ))
93
- argvals <- seq(rangeval [1 ], rangeval [2 ], length = n )
95
+ # construct the argval sequence
96
+ argvals <- seq(a01 [1 ], a01 [2 ], length = n )
97
+ # warning message about the swap
98
+ cat(paste(" 'argvals' is missing; using seq(" , a01 [1 ],
99
+ " , " , a01 [2 ], " , length=" , n , " )\n " ))
100
+ # . return
94
101
return (list (argvals = argvals , y = y , basisobj = basisobj ))
95
102
}
96
103
97
104
# #. --------------------------------------------------------------------------
98
- # # 3. if(length(dim(argvals)) == length(dim(y))) ...
105
+ # # 3. swapping y and argvals
99
106
# #. --------------------------------------------------------------------------
100
107
101
108
dima <- dim(as.array(argvals ))
@@ -214,24 +221,21 @@ argvalsySwap = function(argvals=NULL, y=NULL, basisobj=NULL) {
214
221
215
222
# set up a safety zone for argvals out of range by a tiny amount
216
223
delta <- 1e-7 * (rangeval [2 ]- rangeval [1 ]) # the tiny amount
217
- errwrd <- FALSE
218
224
for (i in 1 : length(argvals )) {
219
225
argi <- argvals [i ]
226
+ # print(argi)
220
227
if (argi < rangeval [1 ] && argi > = rangeval [1 ]- delta ) {
221
228
argi <- rangeval [1 ]
222
- } else {
223
- errwrd <- TRUE
224
229
}
225
230
if (argi > rangeval [2 ] && argi < = rangeval [2 ]+ delta ) {
226
231
argi <- rangeval [2 ]
227
- } else {
228
- errwrd <- TRUE
229
232
}
230
233
}
231
- if (errwrd ) {
234
+ if (any( argvals < rangeval [ 1 ]) || any( argvals > rangeval [ 2 ]) ) {
232
235
# error message
233
236
stop(" There are argvals not contained within interval basisobj$rangeval" )
234
237
}
238
+ return (list (argvals = argvals , y = y , basisobj = basisobj ))
235
239
236
240
}
237
241
0 commit comments