Skip to content

Commit f65b27f

Browse files
Merge pull request #108 from R-Computing-Lab/dev_main
Improve vignette compatibility for missing OpenMx
2 parents c6d566d + 9674d45 commit f65b27f

3 files changed

Lines changed: 156 additions & 111 deletions

File tree

cran-comments.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
# Description
33

4-
This update includes minor enhancements and bug fixes related to how string ids are handled in various functions.
4+
This update includes minor enhancements and bug fixes related to how string ids are handled in various functions. It also now allows certain vignettes to not throw an error if openmx is not installed for older R versions. This should resolve r-oldrel-windows-x86_64 1.5.0 22.00 246.00 268.00 ERROR seen in the last CRAN check.
55

66
# Test Environments
77

88
1. Local OS: Windows 11 x64 (build 26220), R 4.5.2 (2025-10-31 ucrt)
99
2. **GitHub Actions**:
10-
- [Link](https://github.com/R-Computing-Lab/BGmisc/actions/runs/20666823859)
10+
- [Link](https://github.com/R-Computing-Lab/BGmisc/actions/runs/20786177599)
1111
- macOS (latest version) with the latest R release.
1212
- Windows (latest version) with the latest R release.
1313
- Ubuntu (latest version) with:

vignettes/v1_modelingvariancecomponents.Rmd

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,18 @@ This vignette provides a detailed guide to specific functions within the `BGmisc
2424

2525
```{r setup, include=FALSE}
2626
library(BGmisc)
27-
require(EasyMx)
28-
require(OpenMx)
27+
if (!requireNamespace("EasyMx", quietly = TRUE)) {
28+
message("Please install EasyMx to run the model fitting examples.")
29+
} else {
30+
require(EasyMx)
31+
}
32+
if (!requireNamespace("OpenMx", quietly = TRUE)) {
33+
message("Please install OpenMx to run the model fitting examples.")
34+
} else {
35+
require(OpenMx)
36+
}
37+
38+
2939
```
3040

3141
Ensure that the `BGmisc` package is installed and loaded.
@@ -37,7 +47,7 @@ Ensure that the following dependencies are installed before proceeding as they p
3747
- `OpenMx`
3848

3949

40-
```{r}
50+
```r
4151
library(BGmisc)
4252
library(EasyMx)
4353
library(OpenMx)
@@ -88,11 +98,40 @@ identifyComponentModel(
8898

8999
As you can see the model is identified, now that we've added another group. Let us confirm by fitting a model. First we prepare the data.
90100

91-
```{r}
101+
```{r, include=FALSE}
102+
if (!requireNamespace("OpenMx", quietly = TRUE)) {
103+
# if OpenMx isn't available
104+
n_subjects <- 500
92105
require(dplyr)
93-
# require(purrr)
94106
107+
df_summary_data <- data.frame(
108+
age_mean = 34.45,
109+
age_sd = 10.12345,
110+
ht1_mean = 1.662,
111+
ht1_sd = 0.0896277,
112+
ht2_mean = 1.694,
113+
ht2_sd = 0.09903498
114+
)
115+
set.seed(12345)
116+
twinData <- data.frame(
117+
ht1 = rnorm(n_subjects, mean = df_summary_data$ht1_mean, sd = df_summary_data$ht1_sd),
118+
zyg = rep(c(1, 3), each = n_subjects / 2)
119+
)
120+
twinData$ht2 <- twinData$ht1 * ifelse(twinData$zyg == 1, 1, 0.5) +
121+
rnorm(n_subjects, mean = 0, sd = df_summary_data$ht2_sd) + .1*rnorm(n_subjects, mean = df_summary_data$ht2_mean, sd = df_summary_data$ht2_sd)
122+
twinData$ht2[twinData$zyg == 3] <- twinData$ht2[twinData$zyg == 3] + .5*rnorm(sum(twinData$zyg == 3), mean = df_summary_data$ht2_mean, sd = df_summary_data$ht2_sd)
123+
124+
} else {
125+
95126
data(twinData, package = "OpenMx")
127+
}
128+
129+
```
130+
131+
```{r}
132+
require(dplyr)
133+
134+
96135
selVars <- c("ht1", "ht2")
97136
98137
mzdzData <- subset(
@@ -104,11 +143,16 @@ mzdzData$RCoef <- c(1, NA, .5)[mzdzData$zyg]
104143
105144
106145
mzData <- mzdzData %>% filter(zyg == 1)
146+
107147
```
108148

149+
109150
Let us fit the data with MZ twins by themselves.
110151

111152
```{r}
153+
if (!requireNamespace("EasyMx", quietly = TRUE)) {
154+
print("Please install EasyMx to run the model fitting examples.")
155+
} else {
112156
run1 <- emxTwinModel(
113157
model = "Cholesky",
114158
relatedness = "RCoef",
@@ -118,11 +162,15 @@ run1 <- emxTwinModel(
118162
)
119163
120164
summary(run1)
165+
}
121166
```
122167

123168
As you can see the model was unsuccessful because it was not identified. But when we add another group, so that the model is identified, the model now fits.
124169

125170
```{r}
171+
if (!requireNamespace("EasyMx", quietly = TRUE)) {
172+
print("Please install EasyMx to run the model fitting examples.")
173+
} else {
126174
run2 <- emxTwinModel(
127175
model = "Cholesky",
128176
relatedness = "RCoef",
@@ -132,4 +180,5 @@ run2 <- emxTwinModel(
132180
)
133181
134182
summary(run2)
183+
}
135184
```

0 commit comments

Comments
 (0)