Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

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

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.agent.xml

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

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.ask.xml

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

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.ask2agent.xml

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

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.edit.xml

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

8 changes: 8 additions & 0 deletions .idea/interactionR.iml

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

10 changes: 10 additions & 0 deletions .idea/misc.xml

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

8 changes: 8 additions & 0 deletions .idea/modules.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

40 changes: 16 additions & 24 deletions R/interactionR_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#'
#' @param p.value Includes p-values in the generated table if set to TRUE. Default is FALSE.
#'
#' @param file_path An optional user-specified string representing the file path to save the generated Word table instead of the current working directory
#' @param file Optional. File path (directory or full file name) to save the generated Word table. If NULL, the table is not saved. If a directory is provided, the file will be saved as 'interaction_table.docx' in that directory. If a file name is provided, it will be used as is. Default is NULL.
#'
#' @return saves a publication-ready microsoft word Table corresponding to Table 1 or Table 3 respectively in Knol and Vanderweele (2012) to the working directory (with user's permission).
#' It also returns an object of class flextable corresponding to the saved table for further manipulation.
Expand All @@ -33,10 +33,9 @@
#' @import flextable
#' @import officer
#' @export
interactionR_table <- function(obj, p.value = FALSE, file_path = NA) {
interactionR_table <- function(obj, p.value = FALSE, file = NULL) {
if (!is(obj, "interactionR")) {
stop("Argument 'obj' must be an object of class 'interactionR',
use the interactionR() function to generate such object ")
stop("Argument 'obj' must be an object of class 'interactionR',\n use the interactionR() function to generate such object ")
}

beta1 <- obj$exp_names[1]
Expand Down Expand Up @@ -191,28 +190,21 @@ interactionR_table <- function(obj, p.value = FALSE, file_path = NA) {

}

if (!is.na(file_path)) {
# checks if user pre-specified a file path
path <- paste(file_path, "interaction.docx", sep = "\\")
save_as_docx(t2, path = path)
print(paste("The file 'interaction_table.docx' has been saved to", file_path, sep = " "))
if (!is.null(file)) {
if (dir.exists(file)) {
file <- file.path(file, "interaction_table.docx")
} else if (grepl("/$", file)) {
dir.create(file, showWarnings = FALSE, recursive = TRUE)
file <- file.path(file, "interaction_table.docx")
} else if (dirname(file) != "." && !dir.exists(dirname(file))) {
dir.create(dirname(file), showWarnings = FALSE, recursive = TRUE)
}
save_as_docx(t2, path = file)
message(sprintf("The file '%s' has been saved.", file))
print(t2)
invisible(t2)
} else {
uprompt <- askYesNo("Do you want to save a Microsoft Word copy of the em/interaction table to your working directory?", default = FALSE)
# Gets permission from the user to save Word file into the working directory
# Default is NO

if (is.na(uprompt) || !uprompt) {
# if permission is declined or NA, working directory is untouched
print(t2)
invisible(t2)
} else if (uprompt) {
# if permission is given (as Yes), table is saved to working directory and user is informed
save_as_docx(t2, path = "interaction_table.docx")
print(paste("The file 'interaction_table.docx' has been saved to", getwd(), sep = " "))
print(t2)
invisible(t2)
}
print(t2)
invisible(t2)
}
}