Title: | Repeatable Analysis in R |
---|---|
Description: | Set of utilities to facilitate the reproduction of analysis in R. It allow to make_structure(), clean_structure(), and run and log programs in a predefined order to allow secondary files, analysis and reports be constructed in an ordered and reproducible form. |
Authors: | John J. Aponte [aut, cre] |
Maintainer: | John J. Aponte <[email protected]> |
License: | GPL (>= 3) |
Version: | 2.2.0.9000 |
Built: | 2024-11-16 05:51:43 UTC |
Source: | https://github.com/johnaponte/repana |
writeDataTable
Include a data.frame
into a workbook applying a tableStyle and
an auto width to the column. For better results you could setup
options("openxlsx.minWidth" = 6)
addDataTable( wb, df, sheet, tableName, tableStyle = "TableStyleMedium1", withFilter = TRUE, firstActiveCol = NULL, ... )
addDataTable( wb, df, sheet, tableName, tableStyle = "TableStyleMedium1", withFilter = TRUE, firstActiveCol = NULL, ... )
wb |
a workbook object |
df |
a data.frame |
sheet |
the sheet name. If missing the name of the data.frame |
tableName |
a name for the table in the excel document. If missing the name of the data.frame |
tableStyle |
a tableStyle name |
withFilter |
if TRUE the filter is included |
firstActiveCol |
First column active on the the freeze panel |
... |
other parameters for the |
silently the wb
## Not run: library(openxlxs) options("openxlsx.minWidth" = 6) wb <- createWorkbook(title = "Test addDataTable") addDataTable(wb,iris) saveWorkbook(wb, "test_addDataTable.xlsx") ## End(Not run)
## Not run: library(openxlxs) options("openxlsx.minWidth" = 6) wb <- createWorkbook(title = "Test addDataTable") addDataTable(wb,iris) saveWorkbook(wb, "test_addDataTable.xlsx") ## End(Not run)
Helper function to drop all tables from a database
clean_database(con)
clean_database(con)
con |
DBI connection |
invisible, a lit with result from DBI
Delete and make new database
, logs
and reports
directory
clean_structure()
clean_structure()
Invisible, the directories defined by the clean_before_new_analysis entry in the config.yml file.
John J. Aponte
This function get a DBI connection to a database reading the parameters from a
config.yml
file using the get
function.
See the vignette for details.
get_con(configname = "defaultdb", file = "config.yml")
get_con(configname = "defaultdb", file = "config.yml")
configname |
a string with the name of the configuration |
file |
name of the configuration to read from. |
a DBI
connection
John J. Aponte
dirs
section of the config.yml
fileIt is a wrap of config::get("dirs")
.
get_dirs(file = "config.yml")
get_dirs(file = "config.yml")
file |
by default the |
a list with the directory entries
This function get a pool connection to a database reading the parameters from a
config.yml
file using the get
function.
See the vignette for details.
get_pool(configname = "defaultdb", file = "config.yml")
get_pool(configname = "defaultdb", file = "config.yml")
configname |
a string with the name of the value |
file |
name of the configuration to read from. |
a dbPool
connection object
John J. Aponte
RStudio addin app to insert a template to the heading part of a snip code
insert_template()
insert_template()
The template to insert
Make the following directories
data to keep the data necessary for the project
database to keep the secondary, modified dataset and objects
handmade to keep reports and dataset modified by hand or not make by the automatic stream
logs to keep logs of the automatic stream
reports to keep the automatic reports
The data
, handmade
are not clean. The rest are clean as they
should be reproduced by the automatic stream. Do not forget to include them
in .gitignore
if you use git
make_structure()
make_structure()
the dir
structure
John J. Aponte
By default, all programs with the pattern "nn_" will be executed in order. The 'Start' and 'Stop' parameters can be used to modify the files to start or stop at a different number.
master( start = 0, stop = Inf, format = "html", logdir = config::get("dirs")$logs )
master( start = 0, stop = Inf, format = "html", logdir = config::get("dirs")$logs )
start |
program to start |
stop |
program to stop |
format |
Format to render the programs values accepted are "pdf", "html" and "word" |
logdir |
directory to keep the logs of the files. By default
the entry on the |
The files are treated as snip files for rmarkdown and render in the log directory, with the format specified in the format parameter.
The default the log directory is configured in the config.yml file.
a data.frame with the files run, running time and exit status
Run the programs specified by the pattern, in the order as the pattern select the files. Keep a log of the results. By default the pattern starting with two numbers and ending with .R is selected. They are run in order
master_txt( pattern = "^[0-9][0-9].*\\.R$", start = 1, stop = Inf, logdir = config::get("dirs")$logs, rscript_path )
master_txt( pattern = "^[0-9][0-9].*\\.R$", start = 1, stop = Inf, logdir = config::get("dirs")$logs, rscript_path )
pattern |
Regular expression to select the files to run |
start |
index of the program to start |
stop |
index of the program to stop |
logdir |
directory to keep the logs of the files. By default |
rscript_path |
path to the |
The program add (or create if not exists) the files run, time of execution and exit status in the file master.log of the directory logs.
WARNING: This is a legacy program. Use master instead.
a data.frame with the files run, running time and exit status
Render the report and copy it to the outputdir
directory.
More formats are available but only three are included here
'
render_report(report, format = "pdf", outputdir = get_dirs()$reports, ...)
render_report(report, format = "pdf", outputdir = get_dirs()$reports, ...)
report |
filename of the report |
format |
output format. "pdf","html","word" are valid entries |
outputdir |
directory to save the report |
... |
other parameters for |
No return value, called for side effects to render the reports
## Not run: render_report(myreport.rmd,"pdf") ## End(Not run)
## Not run: render_report(myreport.rmd,"pdf") ## End(Not run)
Create of they do not exist the following directories
R
dat
out
targets_structure()
targets_structure()
If does not exists, create a simplify version of the _targets.R
script,
modify the .gitignore
. Also add a config.yml
and a _template.txt
files.
## Not run: targets_structure() ## End(Not run)
## Not run: targets_structure() ## End(Not run)
Helper function to include a data.frame in the database and update the log
update_table(con, table, source, tablename)
update_table(con, table, source, tablename)
con |
DBI connection |
table |
the data.frame to be included in the database |
source |
a manual comment to identify the source of the table |
tablename |
if present, the data frame will be saved with this name. |
the result from DBI
otherwise the name of the data.frame
Make a log of the database updates. If the log table does not exists it creates it Make a new entry with the timestamp of the update
write_log(con, tablename, source)
write_log(con, tablename, source)
con |
DBI connection |
tablename |
the name of the table |
source |
a manual comment to identify the source of the table |
the result from DBI