Skip to content

Commit 95f8424

Browse files
jupyter does not return TRUE + datasummary_balance test fix
1 parent ccfe079 commit 95f8424

7 files changed

+49
-31
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Misc:
1313

1414
* Bugfix: rounding in LaTeX w/ siunitx and NaN entries.
15+
* output='jupyter' no longer prints an extraneousnTRUE to the notebook
1516

1617
# modelsummary 0.9.2
1718

R/datasummary.R

+7-1
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,15 @@ datasummary <- function(formula,
222222
add_rows = add_rows,
223223
...)
224224

225-
if (!is.null(settings_get("output_file"))) {
225+
# invisible return
226+
if (!is.null(settings_get("output_file")) ||
227+
output == "jupyter" ||
228+
(output == "default" && settings_equal("output_default", "jupyter"))) {
229+
settings_rm()
226230
return(invisible(out))
231+
# visible return
227232
} else {
233+
settings_rm()
228234
return(out)
229235
}
230236

R/datasummary_balance.R

+9-5
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,16 @@ datasummary_balance <- function(formula,
233233
escape = escape,
234234
...)
235235

236-
if (!is.null(settings_get("output_file"))) {
237-
settings_rm()
238-
return(invisible(out))
236+
# invisible return
237+
if (!is.null(settings_get("output_file")) ||
238+
output == "jupyter" ||
239+
(output == "default" && settings_equal("output_default", "jupyter"))) {
240+
settings_rm()
241+
return(invisible(out))
242+
# visible return
239243
} else {
240-
settings_rm()
241-
return(out)
244+
settings_rm()
245+
return(out)
242246
}
243247

244248
}

R/datasummary_correlation.R

+6-1
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,14 @@ datasummary_correlation <- function(data,
195195
title = title,
196196
...)
197197

198-
if (!is.null(settings_get("output_file"))) {
198+
199+
# invisible return
200+
if (!is.null(settings_get("output_file")) ||
201+
output == "jupyter" ||
202+
(output == "default" && settings_equal("output_default", "jupyter"))) {
199203
settings_rm()
200204
return(invisible(out))
205+
# visible return
201206
} else {
202207
settings_rm()
203208
return(out)

R/datasummary_skim.R

+1-3
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,12 @@ datasummary_skim_categorical <- function(
355355
f <- All(dat_new, numeric = FALSE, factor = TRUE, logical = TRUE, character = TRUE) ~
356356
(N = 1) * Format() + (`%` = Percent()) * Format(pctformat())
357357

358-
out <- datasummary(
358+
datasummary(
359359
formula = f,
360360
data = dat_new,
361361
output = output,
362362
title = title,
363363
align = align,
364364
notes = notes)
365365

366-
return(out)
367-
368366
}

R/modelsummary.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,13 @@ modelsummary <- function(
428428
...
429429
)
430430

431-
if (!is.null(settings_get("output_file"))) {
431+
# invisible return
432+
if (!is.null(settings_get("output_file")) ||
433+
output == "jupyter" ||
434+
(output == "default" && settings_equal("output_default", "jupyter"))) {
432435
settings_rm()
433436
return(invisible(out))
437+
# visible return
434438
} else {
435439
settings_rm()
436440
return(out)

tests/testthat/_snaps/datasummary_balance.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
\cmidrule(l{3pt}r{3pt}){2-3} \cmidrule(l{3pt}r{3pt}){4-5}
1212
& Mean & Std. Dev. & Mean & Std. Dev. & Diff. in Means & Std. Error\\
1313
\midrule
14-
mpg & 16.6 & 3.9 & 24.6 & 5.4 & \num{7.9} & \num{1.7}\\
15-
cyl & 7.4 & 1.1 & 4.6 & 0.9 & \num{-2.9} & \num{0.4}\\
16-
disp & 307.1 & 106.8 & 132.5 & 56.9 & \num{-174.7} & \num{29.4}\\
17-
hp & 189.7 & 60.3 & 91.4 & 24.4 & \num{-98.4} & \num{15.6}\\
18-
drat & 3.4 & 0.5 & 3.9 & 0.5 & \num{0.5} & \num{0.2}\\
19-
wt & 3.7 & 0.9 & 2.6 & 0.7 & \num{-1.1} & \num{0.3}\\
20-
qsec & 16.7 & 1.1 & 19.3 & 1.4 & \num{2.6} & \num{0.4}\\
21-
am & 0.3 & 0.5 & 0.5 & 0.5 & \num{0.2} & \num{0.2}\\
22-
gear & 3.6 & 0.9 & 3.9 & 0.5 & \num{0.3} & \num{0.2}\\
23-
carb & 3.6 & 1.5 & 1.8 & 1.1 & \num{-1.8} & \num{0.5}\\
14+
mpg & 16.6 & 3.9 & 24.6 & 5.4 & 7.9 & 1.7\\
15+
cyl & 7.4 & 1.1 & 4.6 & 0.9 & -2.9 & 0.4\\
16+
disp & 307.1 & 106.8 & 132.5 & 56.9 & -174.7 & 29.4\\
17+
hp & 189.7 & 60.3 & 91.4 & 24.4 & -98.4 & 15.6\\
18+
drat & 3.4 & 0.5 & 3.9 & 0.5 & 0.5 & 0.2\\
19+
wt & 3.7 & 0.9 & 2.6 & 0.7 & -1.1 & 0.3\\
20+
qsec & 16.7 & 1.1 & 19.3 & 1.4 & 2.6 & 0.4\\
21+
am & 0.3 & 0.5 & 0.5 & 0.5 & 0.2 & 0.2\\
22+
gear & 3.6 & 0.9 & 3.9 & 0.5 & 0.3 & 0.2\\
23+
carb & 3.6 & 1.5 & 1.8 & 1.1 & -1.8 & 0.5\\
2424
\bottomrule
2525
\end{tabular}
2626
\end{table}
@@ -38,16 +38,16 @@
3838
\cmidrule(l{3pt}r{3pt}){2-3} \cmidrule(l{3pt}r{3pt}){4-5}
3939
& Mean & Std. Dev. & Mean & Std. Dev. & Diff. in Means & Std. Error\\
4040
\midrule
41-
mpg & 16.6 & 3.9 & 24.6 & 5.4 & \num{7.9} & \num{1.7}\\
42-
cyl & 7.4 & 1.1 & 4.6 & 0.9 & \num{-2.9} & \num{0.4}\\
43-
disp & 307.1 & 106.8 & 132.5 & 56.9 & \num{-174.7} & \num{29.4}\\
44-
hp & 189.7 & 60.3 & 91.4 & 24.4 & \num{-98.4} & \num{15.6}\\
45-
drat & 3.4 & 0.5 & 3.9 & 0.5 & \num{0.5} & \num{0.2}\\
46-
wt & 3.7 & 0.9 & 2.6 & 0.7 & \num{-1.1} & \num{0.3}\\
47-
qsec & 16.7 & 1.1 & 19.3 & 1.4 & \num{2.6} & \num{0.4}\\
48-
am & 0.3 & 0.5 & 0.5 & 0.5 & \num{0.2} & \num{0.2}\\
49-
gear & 3.6 & 0.9 & 3.9 & 0.5 & \num{0.3} & \num{0.2}\\
50-
carb & 3.6 & 1.5 & 1.8 & 1.1 & \num{-1.8} & \num{0.5}\\
41+
mpg & 16.6 & 3.9 & 24.6 & 5.4 & 7.9 & 1.7\\
42+
cyl & 7.4 & 1.1 & 4.6 & 0.9 & -2.9 & 0.4\\
43+
disp & 307.1 & 106.8 & 132.5 & 56.9 & -174.7 & 29.4\\
44+
hp & 189.7 & 60.3 & 91.4 & 24.4 & -98.4 & 15.6\\
45+
drat & 3.4 & 0.5 & 3.9 & 0.5 & 0.5 & 0.2\\
46+
wt & 3.7 & 0.9 & 2.6 & 0.7 & -1.1 & 0.3\\
47+
qsec & 16.7 & 1.1 & 19.3 & 1.4 & 2.6 & 0.4\\
48+
am & 0.3 & 0.5 & 0.5 & 0.5 & 0.2 & 0.2\\
49+
gear & 3.6 & 0.9 & 3.9 & 0.5 & 0.3 & 0.2\\
50+
carb & 3.6 & 1.5 & 1.8 & 1.1 & -1.8 & 0.5\\
5151
\bottomrule
5252
\end{tabular}
5353
\end{table}

0 commit comments

Comments
 (0)