Skip to content

Commit b76ca64

Browse files
Merge pull request #879 from vincentarelbundock/issue878
Issue #878
2 parents 1e576ce + 5108c4d commit b76ca64

15 files changed

+567
-504
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Description: Create beautiful and customizable tables to summarize several
1010
RTF, JPG, or PNG. Tables can easily be embedded in 'Rmarkdown' or 'knitr'
1111
dynamic documents. Details can be found in Arel-Bundock (2022)
1212
<doi:10.18637/jss.v103.i01>.
13-
Version: 2.3.0.5
13+
Version: 2.3.0.6
1414
Authors@R: c(person("Vincent", "Arel-Bundock",
1515
email = "[email protected]",
1616
role = c("aut", "cre"),

NEWS.qmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Bug:
2121
Misc:
2222

2323
* Allow `tinytable`-style note specification: `notes=list(a = list(i = 0:1, j = 1, text = "Blah."))`. Thanks to @sverrirarnors for feature request #867.
24+
* `exponentiate=TRUE` no longer exponentiates parameters that are marked as "random" in the "effect" column when calling `get_estimates()`. Thanks to @orvaquim for report #878.
2425

2526
## 2.3.0
2627

R/format_estimates.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,18 @@ format_estimates <- function(
113113
# standard error before transforming estimate
114114
cols <- c("std.error", "estimate", "conf.low", "conf.high")
115115
cols <- intersect(cols, colnames(est))
116+
117+
# Create a mask for non-random effects
118+
non_random <- rep(TRUE, nrow(est))
119+
if (all(c("term", "effect") %in% colnames(est))) {
120+
non_random <- ifelse(grepl("^SD |^Cor ", est$term) & est$effect == "random", FALSE, TRUE)
121+
}
122+
116123
for (col in cols) {
117124
if (col == "std.error") {
118-
est[["std.error"]] <- exp(est[["estimate"]]) * est[["std.error"]]
125+
est[["std.error"]][non_random] <- exp(est[["estimate"]][non_random]) * est[["std.error"]][non_random]
119126
} else if (col %in% c("estimate", "conf.low", "conf.high")) {
120-
est[[col]] <- exp(est[[col]])
127+
est[[col]][non_random] <- exp(est[[col]][non_random])
121128
}
122129
}
123130
}

R/modelsummary.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ globalVariables(c(
116116
#' @param exponentiate TRUE, FALSE, or logical vector of length equal to the
117117
#' number of models. If TRUE, the `estimate`, `conf.low`, and `conf.high`
118118
#' statistics are exponentiated, and the `std.error` is transformed to
119-
#' `exp(estimate)*std.error`.
119+
#' `exp(estimate)*std.error`. The `exponentiate` argument is ignored for
120+
#' distributional random effects parameters (SD and Cor).
120121
#' @param coef_map character vector. Subset, rename, and reorder coefficients.
121122
#' Coefficients omitted from this vector are omitted from the table. The order
122123
#' of the vector determines the order of the table. `coef_map` can be a named

inst/tinytest/_tinysnapshot/escape-escape.html

Lines changed: 83 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
function styleCell_m4thvn8u3cwpmj8hiuwk(i, j, css_id) {
1616
var table = document.getElementById("tinytable_m4thvn8u3cwpmj8hiuwk");
17-
var cell = table.rows[i]?.cells[j]; // Safe navigation to avoid errors
17+
var cell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
1818
if (cell) {
1919
console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
2020
cell.classList.add(css_id);
@@ -24,52 +24,57 @@
2424
}
2525
function insertSpanRow(i, colspan, content) {
2626
var table = document.getElementById('tinytable_m4thvn8u3cwpmj8hiuwk');
27-
var newRow = table.insertRow(i);
27+
// Find the row with data-row attribute matching i
28+
var targetRow = table.querySelector(`tr [data-row="${i}"]`).closest('tr');
29+
var newRow = table.insertRow(targetRow.rowIndex);
2830
var newCell = newRow.insertCell(0);
2931
newCell.setAttribute("colspan", colspan);
32+
newCell.setAttribute("data-col", "0");
33+
newCell.setAttribute("data-row", i - 1);
3034
// newCell.innerText = content;
3135
// this may be unsafe, but innerText does not interpret <br>
3236
newCell.innerHTML = content;
3337
}
3438
function spanCell_m4thvn8u3cwpmj8hiuwk(i, j, rowspan, colspan) {
3539
var table = document.getElementById("tinytable_m4thvn8u3cwpmj8hiuwk");
36-
const targetRow = table.rows[i];
37-
const targetCell = targetRow.cells[j];
40+
const targetCell = table.querySelector(`[data-row="${i}"][data-col="${j}"]`);
41+
if (!targetCell) {
42+
console.warn(`Cell at (${i}, ${j}) not found.`);
43+
}
44+
45+
// Get all cells that need to be removed
46+
const cellsToRemove = [];
3847
for (let r = 0; r < rowspan; r++) {
39-
// Only start deleting cells to the right for the first row (r == 0)
40-
if (r === 0) {
41-
// Delete cells to the right of the target cell in the first row
42-
for (let c = colspan - 1; c > 0; c--) {
43-
if (table.rows[i + r].cells[j + c]) {
44-
table.rows[i + r].deleteCell(j + c);
45-
}
46-
}
47-
}
48-
// For rows below the first, delete starting from the target column
49-
if (r > 0) {
50-
for (let c = colspan - 1; c >= 0; c--) {
51-
if (table.rows[i + r] && table.rows[i + r].cells[j]) {
52-
table.rows[i + r].deleteCell(j);
53-
}
48+
for (let c = 0; c < colspan; c++) {
49+
if (r === 0 && c === 0) continue; // Skip the target cell
50+
const cell = table.querySelector(`[data-row="${i + r}"][data-col="${j + c}"]`);
51+
if (cell) {
52+
cellsToRemove.push(cell);
5453
}
5554
}
5655
}
57-
// Set rowspan and colspan of the target cell
58-
targetCell.rowSpan = rowspan;
59-
targetCell.colSpan = colspan;
56+
57+
// Remove all cells
58+
cellsToRemove.forEach(cell => cell.remove());
59+
60+
// Set rowspan and colspan of the target cell if it exists
61+
if (targetCell) {
62+
targetCell.rowSpan = rowspan;
63+
targetCell.colSpan = colspan;
64+
}
6065
}
6166
// tinytable span after
6267
window.addEventListener('load', function () {
6368
var cellsToStyle = [
6469
// tinytable style arrays after
65-
{ positions: [ { i: 15, j: 1 }, { i: 15, j: 2 }, ], css_id: 'tinytable_css_u5i4tb8acz516c5lsr29',},
66-
{ positions: [ { i: 8, j: 2 }, { i: 8, j: 1 }, ], css_id: 'tinytable_css_iox90hlcz6p88f470o4c',},
67-
{ positions: [ { i: 1, j: 1 }, { i: 2, j: 1 }, { i: 4, j: 1 }, { i: 5, j: 1 }, { i: 6, j: 1 }, { i: 7, j: 1 }, { i: 5, j: 2 }, { i: 9, j: 1 }, { i: 10, j: 1 }, { i: 11, j: 1 }, { i: 12, j: 1 }, { i: 13, j: 1 }, { i: 14, j: 1 }, { i: 12, j: 2 }, { i: 3, j: 1 }, { i: 1, j: 2 }, { i: 2, j: 2 }, { i: 3, j: 2 }, { i: 4, j: 2 }, { i: 9, j: 2 }, { i: 6, j: 2 }, { i: 7, j: 2 }, { i: 13, j: 2 }, { i: 10, j: 2 }, { i: 11, j: 2 }, { i: 14, j: 2 }, ], css_id: 'tinytable_css_87pizrt6gpue7tq68k7m',},
68-
{ positions: [ { i: 0, j: 1 }, { i: 0, j: 2 }, ], css_id: 'tinytable_css_5jsz1u1bau6rax203jg7',},
69-
{ positions: [ { i: 15, j: 0 }, ], css_id: 'tinytable_css_evu8i6m1snsv5kmmasu3',},
70-
{ positions: [ { i: 8, j: 0 }, ], css_id: 'tinytable_css_ue01fe9hmaas4mta0vfc',},
71-
{ positions: [ { i: 1, j: 0 }, { i: 2, j: 0 }, { i: 3, j: 0 }, { i: 4, j: 0 }, { i: 5, j: 0 }, { i: 6, j: 0 }, { i: 7, j: 0 }, { i: 12, j: 0 }, { i: 9, j: 0 }, { i: 10, j: 0 }, { i: 11, j: 0 }, { i: 13, j: 0 }, { i: 14, j: 0 }, ], css_id: 'tinytable_css_dcq09jxgyitf4or5kg1s',},
72-
{ positions: [ { i: 0, j: 0 }, ], css_id: 'tinytable_css_qnddps3hrarwxnclv9tv',},
70+
{ positions: [ { i: '15', j: 1 }, { i: '15', j: 2 }, ], css_id: 'tinytable_css_u5i4tb8acz516c5lsr29',},
71+
{ positions: [ { i: '8', j: 2 }, { i: '8', j: 1 }, ], css_id: 'tinytable_css_iox90hlcz6p88f470o4c',},
72+
{ positions: [ { i: '1', j: 1 }, { i: '2', j: 1 }, { i: '4', j: 1 }, { i: '5', j: 1 }, { i: '6', j: 1 }, { i: '7', j: 1 }, { i: '5', j: 2 }, { i: '9', j: 1 }, { i: '10', j: 1 }, { i: '11', j: 1 }, { i: '12', j: 1 }, { i: '13', j: 1 }, { i: '14', j: 1 }, { i: '12', j: 2 }, { i: '3', j: 1 }, { i: '1', j: 2 }, { i: '2', j: 2 }, { i: '3', j: 2 }, { i: '4', j: 2 }, { i: '9', j: 2 }, { i: '6', j: 2 }, { i: '7', j: 2 }, { i: '13', j: 2 }, { i: '10', j: 2 }, { i: '11', j: 2 }, { i: '14', j: 2 }, ], css_id: 'tinytable_css_87pizrt6gpue7tq68k7m',},
73+
{ positions: [ { i: '0', j: 1 }, { i: '0', j: 2 }, ], css_id: 'tinytable_css_5jsz1u1bau6rax203jg7',},
74+
{ positions: [ { i: '15', j: 0 }, ], css_id: 'tinytable_css_evu8i6m1snsv5kmmasu3',},
75+
{ positions: [ { i: '8', j: 0 }, ], css_id: 'tinytable_css_ue01fe9hmaas4mta0vfc',},
76+
{ positions: [ { i: '1', j: 0 }, { i: '2', j: 0 }, { i: '3', j: 0 }, { i: '4', j: 0 }, { i: '5', j: 0 }, { i: '6', j: 0 }, { i: '7', j: 0 }, { i: '12', j: 0 }, { i: '9', j: 0 }, { i: '10', j: 0 }, { i: '11', j: 0 }, { i: '13', j: 0 }, { i: '14', j: 0 }, ], css_id: 'tinytable_css_dcq09jxgyitf4or5kg1s',},
77+
{ positions: [ { i: '0', j: 0 }, ], css_id: 'tinytable_css_qnddps3hrarwxnclv9tv',},
7378
];
7479

7580
// Loop over the arrays to style the cells
@@ -97,87 +102,87 @@
97102
<thead>
98103

99104
<tr>
100-
<th scope="col"> </th>
101-
<th scope="col">First&Second</th>
102-
<th scope="col">Third_Fourth</th>
105+
<th scope="col" data-row="0" data-col="0"> </th>
106+
<th scope="col" data-row="0" data-col="1">First&Second</th>
107+
<th scope="col" data-row="0" data-col="2">Third_Fourth</th>
103108
</tr>
104109
</thead>
105110

106111
<tbody>
107112
<tr>
108-
<td>(Intercept)</td>
109-
<td>-103.772</td>
110-
<td>-103.772</td>
113+
<td data-row="1" data-col="0">(Intercept)</td>
114+
<td data-row="1" data-col="1">-103.772</td>
115+
<td data-row="1" data-col="2">-103.772</td>
111116
</tr>
112117
<tr>
113-
<td></td>
114-
<td>(103.551)</td>
115-
<td>(103.551)</td>
118+
<td data-row="2" data-col="0"></td>
119+
<td data-row="2" data-col="1">(103.551)</td>
120+
<td data-row="2" data-col="2">(103.551)</td>
116121
</tr>
117122
<tr>
118-
<td>under_score</td>
119-
<td>-3.899</td>
120-
<td>-3.899</td>
123+
<td data-row="3" data-col="0">under_score</td>
124+
<td data-row="3" data-col="1">-3.899</td>
125+
<td data-row="3" data-col="2">-3.899</td>
121126
</tr>
122127
<tr>
123-
<td></td>
124-
<td>(2.072)</td>
125-
<td>(2.072)</td>
128+
<td data-row="4" data-col="0"></td>
129+
<td data-row="4" data-col="1">(2.072)</td>
130+
<td data-row="4" data-col="2">(2.072)</td>
126131
</tr>
127132
<tr>
128-
<td>oh&yeah<sup>2</sup></td>
129-
<td>29.329</td>
130-
<td>29.329</td>
133+
<td data-row="5" data-col="0">oh&yeah<sup>2</sup></td>
134+
<td data-row="5" data-col="1">29.329</td>
135+
<td data-row="5" data-col="2">29.329</td>
131136
</tr>
132137
<tr>
133-
<td></td>
134-
<td>(7.169)</td>
135-
<td>(7.169)</td>
138+
<td data-row="6" data-col="0"></td>
139+
<td data-row="6" data-col="1">(7.169)</td>
140+
<td data-row="6" data-col="2">(7.169)</td>
136141
</tr>
137142
<tr>
138-
<td>drat</td>
139-
<td>40.961</td>
140-
<td>40.961</td>
143+
<td data-row="7" data-col="0">drat</td>
144+
<td data-row="7" data-col="1">40.961</td>
145+
<td data-row="7" data-col="2">40.961</td>
141146
</tr>
142147
<tr>
143-
<td></td>
144-
<td>(17.115)</td>
145-
<td>(17.115)</td>
148+
<td data-row="8" data-col="0"></td>
149+
<td data-row="8" data-col="1">(17.115)</td>
150+
<td data-row="8" data-col="2">(17.115)</td>
146151
</tr>
147152
<tr>
148-
<td>Num.Obs.</td>
149-
<td>32</td>
150-
<td>32</td>
153+
<td data-row="9" data-col="0">Num.Obs.</td>
154+
<td data-row="9" data-col="1">32</td>
155+
<td data-row="9" data-col="2">32</td>
151156
</tr>
152157
<tr>
153-
<td>R2</td>
154-
<td>0.759</td>
155-
<td>0.759</td>
158+
<td data-row="10" data-col="0">R2</td>
159+
<td data-row="10" data-col="1">0.759</td>
160+
<td data-row="10" data-col="2">0.759</td>
156161
</tr>
157162
<tr>
158-
<td>R2 Adj.</td>
159-
<td>0.733</td>
160-
<td>0.733</td>
163+
<td data-row="11" data-col="0">R2 Adj.</td>
164+
<td data-row="11" data-col="1">0.733</td>
165+
<td data-row="11" data-col="2">0.733</td>
161166
</tr>
162167
<tr>
163-
<td>AIC</td>
164-
<td>324.9</td>
165-
<td>324.9</td>
168+
<td data-row="12" data-col="0">AIC</td>
169+
<td data-row="12" data-col="1">324.9</td>
170+
<td data-row="12" data-col="2">324.9</td>
166171
</tr>
167172
<tr>
168-
<td>BIC</td>
169-
<td>332.2</td>
170-
<td>332.2</td>
173+
<td data-row="13" data-col="0">BIC</td>
174+
<td data-row="13" data-col="1">332.2</td>
175+
<td data-row="13" data-col="2">332.2</td>
171176
</tr>
172177
<tr>
173-
<td>Log.Lik.</td>
174-
<td>-157.443</td>
175-
<td>-157.443</td>
178+
<td data-row="14" data-col="0">Log.Lik.</td>
179+
<td data-row="14" data-col="1">-157.443</td>
180+
<td data-row="14" data-col="2">-157.443</td>
176181
</tr>
177182
<tr>
178-
<td>RMSE</td>
179-
<td>33.15</td>
180-
<td>33.15</td>
183+
<td data-row="15" data-col="0">RMSE</td>
184+
<td data-row="15" data-col="1">33.15</td>
185+
<td data-row="15" data-col="2">33.15</td>
181186
</tr>
182187
</tbody>
183188
</table>

0 commit comments

Comments
 (0)