Skip to content

Commit

Permalink
Enables passing placement = NULL to apa_table().
Browse files Browse the repository at this point in the history
This ensure that the placement option, which is displayed in the text if used in appendices, can be omitted.
  • Loading branch information
crsh committed Mar 18, 2022
1 parent f220612 commit 489fdb3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 33 deletions.
7 changes: 6 additions & 1 deletion R/apa_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
#' 5 cm. Similarly, to space columns equally use
#' `align = paste0("m{", 1/(ncol(x) + 1), "\\linewidth}")`
#'
#' Note that placement options are not supported in appendices of `apa6`
#' documents and will be printed to the document. To omit the printed options
#' set `placement = NULL`.
#'
#' @seealso \code{\link[knitr]{kable}}, \code{\link{apa_num}}
#' @examples
#'
Expand Down Expand Up @@ -315,7 +319,7 @@ apa_table.data.frame <- function(
if(!is.null(format.args)) validate(format.args, check_class = "list")

validate(escape, check_class = "logical", check_length = 1)
validate(placement, check_class = "character", check_length = 1)
if(!is.null(placement)) validate(placement, check_class = "character", check_length = 1)
validate(landscape, check_class = "logical", check_length = 1)

# Set defaults and rename ellipsis arguments
Expand Down Expand Up @@ -532,6 +536,7 @@ apa_table.latex <- function(

# Print table
place_opt <- paste0("[", placement, "]")
if(place_opt == "[]") place_opt <- NULL

table_output <- "\n\n"

Expand Down
4 changes: 4 additions & 0 deletions man/apa_table.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/testthat/test_apa_table.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract: |
keywords : "keywords"
wordcount : "X"

floatsintext : no
floatsintext : yes
figurelist : no
tablelist : no
footnotelist : no
Expand Down Expand Up @@ -58,6 +58,7 @@ apa_table(
, caption = "0 Single row table."
, note = "This table was created using apa_table()"
, small = TRUE
, placement = NULL
)
```

Expand Down
67 changes: 36 additions & 31 deletions tests/testthat/test_apa_table.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
english,
man]{apa6}
man,floatsintext]{apa6}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\usepackage{amssymb}
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
Expand Down Expand Up @@ -111,6 +109,15 @@
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
\ifLuaTeX
\usepackage[bidi=basic]{babel}
\else
\usepackage[bidi=default]{babel}
\fi
\babelprovide[main,import]{english}
% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}
% Manuscript styling
\usepackage{upgreek}
\captionsetup{font=singlespacing,justification=justified}
Expand All @@ -126,9 +133,9 @@

% Create new environments so endfloat can handle them
% \newenvironment{ltable}
% {\begin{landscape}\begin{center}\begin{threeparttable}}
% {\end{threeparttable}\end{center}\end{landscape}}
\newenvironment{lltable}{\begin{landscape}\begin{center}\begin{ThreePartTable}}{\end{ThreePartTable}\end{center}\end{landscape}}
% {\begin{landscape}\centering\begin{threeparttable}}
% {\end{threeparttable}\end{landscape}}
\newenvironment{lltable}{\begin{landscape}\centering\begin{ThreePartTable}}{\end{ThreePartTable}\end{landscape}}

% Enables adjusting longtable caption width to table width
% Solution found at https://golatex.de/longtable-mit-caption-so-breit-wie-die-tabelle-t15767.html
Expand Down Expand Up @@ -166,26 +173,21 @@
{\section*{\protect\normalfont{\@title}}}
{}{\typeout{Failed to patch title.}}
\makeatother
\shorttitle{Title}
\keywords{keywords\newline\indent Word count: X}
\DeclareDelayedFloatFlavor{ThreePartTable}{table}
\DeclareDelayedFloatFlavor{lltable}{table}
\DeclareDelayedFloatFlavor*{longtable}{table}

\usepackage{xpatch}
\makeatletter
\renewcommand{\efloat@iwrite}[1]{\immediate\expandafter\protected@write\csname efloat@post#1\endcsname{}}
\makeatother
\xapptocmd\appendix
{\xapptocmd\section
{\addcontentsline{toc}{section}{\appendixname\ifoneappendix\else~\theappendix\fi\\: #1}}
{}{\InnerPatchFailed}%
}
{}{\PatchFailed}
\keywords{keywords\newline\indent Word count: X}
\usepackage{lineno}

\linenumbers
\usepackage{csquotes}
\ifxetex
% Load polyglossia as late as possible: uses bidi with RTL langages (e.g. Hebrew, Arabic)
\usepackage{polyglossia}
\setmainlanguage[]{english}
\else
\usepackage[shorthands=off,main=english]{babel}
\fi
\ifluatex
\ifLuaTeX
\usepackage{selnolig} % disable illegal ligatures
\fi

Expand All @@ -194,6 +196,8 @@
\date{}


\shorttitle{Title}

\authornote{

Correspondence concerning this article should be addressed to First Author, Postal address. E-mail: \href{mailto:[email protected]}{\nolinkurl{[email protected]}}
Expand All @@ -202,7 +206,7 @@

\affiliation{\vspace{0.5cm}\textsuperscript{1} Wilhelm-Wundt-University\\\textsuperscript{2} Konstanz Business School}

\abstract{
\abstract{%
Enter abstract here (note the indentation, if you start a new paragraph).
}

Expand All @@ -223,11 +227,12 @@
\NormalTok{ , }\AttributeTok{caption =} \StringTok{"0 Single row table."}
\NormalTok{ , }\AttributeTok{note =} \StringTok{"This table was created using apa\_table()"}
\NormalTok{ , }\AttributeTok{small =} \ConstantTok{TRUE}
\NormalTok{ , }\AttributeTok{placement =} \ConstantTok{NULL}
\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{table}[tbp]
\begin{table}

\begin{center}
\begin{threeparttable}
Expand Down Expand Up @@ -1030,11 +1035,11 @@
\toprule
Predictor & \multicolumn{1}{c}{$b$} & \multicolumn{1}{c}{95\% CI} & \multicolumn{1}{c}{$z$} & \multicolumn{1}{c}{$p$}\\
\midrule
Intercept & 3.04 & [2.70, 3.37] & 17.81 & < .001\\
Outcome2 & -0.45 & [-0.86, -0.06] & -2.25 & .025\\
Outcome3 & -0.29 & [-0.68, 0.08] & -1.52 & .128\\
Treatment2 & 0.00 & [-0.39, 0.39] & 0.00 & > .999\\
Treatment3 & 0.00 & [-0.39, 0.39] & 0.00 & > .999\\
Intercept & 3.04 & {}[2.70, 3.37] & 17.81 & < .001\\
Outcome2 & -0.45 & {}[-0.86, -0.06] & -2.25 & .025\\
Outcome3 & -0.29 & {}[-0.68, 0.08] & -1.52 & .128\\
Treatment2 & 0.00 & {}[-0.39, 0.39] & 0.00 & > .999\\
Treatment3 & 0.00 & {}[-0.39, 0.39] & 0.00 & > .999\\
\bottomrule
\end{tabular}
Expand Down

0 comments on commit 489fdb3

Please sign in to comment.