Skip to content

Commit 98a0dd7

Browse files
authored
try to circumvent Formula length bug with RStudio (#24)
* try to circumvent Formula length bug with RStudio * add missing documentation * avoid call to unexported function length from Formula * update news & description --------- Co-authored-by: Guillaume Cornu <gcornu@cirad.fr>
1 parent 76ee5c0 commit 98a0dd7

File tree

8 files changed

+26
-7
lines changed

8 files changed

+26
-7
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Description:
55
An extension of the Fisher Scoring Algorithm to combine PLS regression with GLM
66
estimation in the multivariate context. Covariates can also be grouped in themes.
77
Version: 3.0.9000
8-
Date: 2022-12-14
8+
Date: 2024-02-24
99
Authors@R: c(
1010
person("Guillaume","Cornu",,"gcornu@cirad.fr", role=c("aut","cre"), comment=c(ORCID="0000-0002-7523-5176")),
1111
person("Frederic","Mortier",,"fmortier@cirad.fr",role="aut", comment=c(ORCID="0000-0001-5473-709X")),
@@ -25,5 +25,5 @@ Imports:
2525
Suggests:
2626
future,future.apply,progressr
2727
LazyData: yes
28-
RoxygenNote: 7.2.3
28+
RoxygenNote: 7.3.2
2929
Encoding: UTF-8

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
S3method("$",MultivariateFormula)
44
S3method(barplot,SCGLR)
55
S3method(barplot,SCGLRTHM)
6+
S3method(length,MultivariateFormula)
67
S3method(pairs,SCGLR)
78
S3method(plot,SCGLR)
9+
S3method(plot,SCGLRCV)
810
S3method(plot,SCGLRTHM)
911
S3method(print,MultivariateFormula)
1012
S3method(print,SCGLR)
13+
S3method(print,SCGLRCV)
1114
S3method(print,summary.SCGLR)
1215
S3method(screeplot,SCGLR)
1316
S3method(screeplot,SCGLRTHM)
1417
S3method(summary,SCGLR)
18+
S3method(summary,SCGLRCV)
1519
export(critConvergence)
1620
export(infoCriterion)
1721
export(kCompRand)

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- fix contrasts error in `scglrTheme` (issue #20)
1111
- fix some URL in docs
1212
- move from `plsdepot::plsreg2` to `pls::plsr` to initialize mixed model components (issue #22)
13+
- fix rstudio bug displaying error message when printing a MultivariateFormula (in fact a Formula) (issue #23).
1314

1415
## New features
1516
- preliminary integration of code from `SCnext/mixedSCGLR` written by Jocelyn Chauvet (issue #11)

R/multivariateFormula.r

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ print.MultivariateFormula <- function(x, ...) {
229229
invisible(x)
230230
}
231231

232+
#' @export
233+
length.MultivariateFormula <- function(x) {
234+
3
235+
}
236+
232237
# print(multivariateFormula("y","1"))
233238
# print(multivariateFormula(y1+y2~x1+x2|x3+x4|x5+x6*x7||a1+a2))
234239
# print(multivariateFormula(c("y1","y2"),list(c("x1","x2"),c("x3","x4")),c("x5","x6*x7"),additional = TRUE))

R/scglr.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ scglr <- function(formula,data,family,K=1,size=NULL,weights=NULL,offset=NULL,su
108108
y <- as.matrix(model.part(form,data=mf,lhs=1))
109109
x <- model.part(form, data=mf, rhs = 1)
110110

111-
if(length(form)[2]==2){
111+
if(length_Formula(form)[2]==2){
112112
AX <- model.part(form, data=mf, lhs=0, rhs = 2)
113113
namesAx <- names(AX)
114114
AX <- model.matrix(form,data=mf,rhs=2)[,-1]

R/scglrCrossVal.r

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,17 @@ scglrCrossVal <- function(formula,data,family,K=1,folds=10,type="mspe",size=NUL
280280
return(cv)
281281
}
282282

283+
#' @export
283284
summary.SCGLRCV <- function(object, ...) {
284285
NextMethod(...)
285286
}
287+
288+
#' @export
286289
print.SCGLRCV <- function(x, ...) {
287290
NextMethod(...)
288291
}
292+
293+
#' @export
289294
plot.SCGLRCV <- function(x, ...) {
290295
tmp <- colMeans(log(x))
291296
ggplot()+

R/theme.r

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ scglrTheme <- function(formula, data, H, family, size = NULL, weights = NULL,
7272

7373
# extract left-hand side (Y)
7474
# Y is a formula of the form ~...
75-
if(length(formula)[1] != 1)
75+
if(length_Formula(formula)[1] != 1)
7676
stop("Left hand side part of formula (Y) must have ONE part!")
7777
theme_Y <- stats::terms(formula, lhs=1, rhs=0)
7878
Y_vars <- all.vars(theme_Y)
@@ -114,15 +114,15 @@ scglrTheme <- function(formula, data, H, family, size = NULL, weights = NULL,
114114
# check and process themes #######################################################################
115115

116116
# check part counts
117-
if(length(formula)[2] < 1+additional)
117+
if(length_Formula(formula)[2] < 1+additional)
118118
if(additional) {
119119
stop("Right hand side part of formula with additional variables must have at least TWO parts!")
120120
} else {
121121
stop("Right hand side part of formula must have at least ONE part!")
122122
}
123123

124124
# theme count
125-
theme_R <- length(formula)[2] - additional
125+
theme_R <- length_Formula(formula)[2] - additional
126126

127127
# check H (number of components to keep per theme)
128128
H <- as.integer(H)
@@ -154,7 +154,7 @@ scglrTheme <- function(formula, data, H, family, size = NULL, weights = NULL,
154154
# extract additional variables (A)
155155
# A is a formula of the form ~...
156156
if(additional) {
157-
theme_A <- stats::terms(formula, lhs=0, rhs=length(formula)[[2]])
157+
theme_A <- stats::terms(formula, lhs=0, rhs=length_Formula(formula)[[2]])
158158
} else {
159159
theme_A <- NULL
160160
}

R/utils.r

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@ custom_stop <- function(subclass, ..., call=sys.call(-1)) {
7272
c <- condition(c(subclass, "error"), message=message, call=call)
7373
stop(c)
7474
}
75+
76+
length_Formula <- function(x) {
77+
c(length(attr(x, "lhs")), length(attr(x, "rhs")))
78+
}

0 commit comments

Comments
 (0)