Skip to content

Commit

Permalink
📝 flesh out vignette about tblDown()
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Cazelles committed Apr 10, 2020
1 parent 421d355 commit c141150
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Makefile
inst/tmp
docs/
*.odt


# History files
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
on:
branch: master
local_dir: docs
- stage: unit tests
os: osx
r: release
# - stage: unit tests
# os: osx
# r: release
- stage: unit tests
os: linux
dist: bionic
Expand Down
2 changes: 1 addition & 1 deletion R/tblDown.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Write data frames in a document
#'
#' Export a data frame or a list of data frames in a document using pandoc.
#' Write a data frame or a list of data frames in a markdown document converted #' in various format using pandoc.
#'
#' @param x a data frame or a list of data frames.
#' @param output_file path to the output file. Its extension will be used by
Expand Down
2 changes: 1 addition & 1 deletion man/tblDown.Rd

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

71 changes: 70 additions & 1 deletion vignettes/overview.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,76 @@ tblDown(list(CO2[1:2, ], CO2[3:6,]), "./tables.docx",

# Messages

It is somewhat convenient to have standardized messages when u
`inSilecoMisc` includes four simple message functions to standardize messages in scripts:

```{R}
# 1. msgInfo() indicates what the upcoming computation
msgInfo("this is what's gonna happen next")
```

```{R}
# 2. msgWarning() reminds me something important that should not affect the run
msgWarning("Got to be careful")
```

```{R}
# 3. msgError() when something went wrong (and I anticipated that it could happen)
msgError("Something wrong")
```

```{R}
# 4. msgSuccess() when a step/ a computation has been successfully completed
msgSuccess("All good")
```

They are meant to help structuring scripts, here is a somewhat contrived example:

```{R}
scr_min <- function() {
# msgInfo() lets me know where I am in the script
msgInfo("Average random values")
set.seed(111)
out <- mean(runif(100))
msgSuccess("Done!")
# msgSuccess() indicates the successful completion of this part
out
}
scr_min()
```

As these functions are based on `message()`, one can execute the script quietly by calling `suppressMessages()` beforehand:

```{R}
# quiet run
suppressMessages(scr_min())
```


# Writing tables in document

`tblDown()` writes a data frame (and list of data frame) in a document in various formats (`.docx` by default)

```{R, eval = FALSE}
# NB tblDown(head(CO2)) creates table.docx by default
tblDown(head(CO2), output_file = "table.odt")
```

![](table_odt.png)

`tblDown()` handles lists of data frames and the user can also pass a set of captions for every table and even separate them with section headers:

```{R, eval = FALSE}
tblDown(list(head(CO2), tail(CO2)), output_file = "tables.pdf",
caption = c("This is the head of CO2", "This is the tail of CO2"),
section = "Table")
```

![](tables_pdf.png)

Note that if there are less captions or sections titles than data frames,
vectors of captions (and/or sections) are repeated and an index is appended.




# Mathematical functions
Expand Down
Binary file added vignettes/table_odt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/tables_pdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c141150

Please sign in to comment.