Skip to content
Snippets Groups Projects
Commit c1e4ffae authored by B.Anderson's avatar B.Anderson
Browse files

place to store .Rmd with worked example to list all UKDA archive data files

parent 59c497b1
Branches
No related tags found
No related merge requests found
# Rmd
A place to put .Rmd files.
In general .Rmd scripts get called by .R makefiles so that knitted outputs can go into `/docs` for publishing via github/gitlab pages (if you wish).
\ No newline at end of file
# runs testFiles.Rmd
require(saveData)
source(paste0(here::here(), "/.RProfile")) # re-sets project parameters
# remember most repo parameters are in repoParams.R which gets sourced by .RProfile on
# project open. XX need to test if still works if library loaded in a different project XX
makeReport <- function(inF, outF){
# default = html
rmarkdown::render(input = inF,
params = list(title = title,
subtitle = subtitle,
authors = authors),
output_file = outF
)
}
# code ----
# > Make report ----
# >> yaml ----
version <- "1.0"
title <- paste0("SAVE Data")
subtitle <- paste0("UKDA archive file listing report v", version)
authors <- "Ben Anderson (b.anderson@soton.ac.uk)"
# >> run report ----
rmdFile <- "testFiles"
inF <- paste0(projParams$projLoc, "/Rmd/", rmdFile,".Rmd")
outF <- paste0(projParams$projLoc,"/docs/",rmdFile, "_" , version, ".html")
makeReport(inF, outF)
---
params:
subtitle: ""
title: ""
authors: ""
title: '`r params$title`'
subtitle: '`r params$subtitle`'
author: '`r params$authors`'
date: 'Last run at: `r Sys.time()`'
output:
bookdown::html_document2:
fig_caption: yes
code_folding: hide
number_sections: yes
toc: yes
toc_depth: 2
toc_float: TRUE
bookdown::pdf_document2:
fig_caption: yes
number_sections: yes
bookdown::word_document2:
fig_caption: yes
number_sections: yes
toc: yes
toc_depth: 2
fig_width: 5
always_allow_html: yes
bibliography: '`r paste0(here::here(), "/bibliography.bib")`'
---
```{r setup, include=FALSE}
# Set start time ----
startTime <- proc.time()
# set params ----
knitr::opts_chunk$set(echo = TRUE)
# libraries
require(data.table)
require(kableExtra)
# functions ----
getFileList <- function(p){
# check for files in a given path
message("Checking for data files in ", p)
all.files <- list.files(path = p, recursive = TRUE, full.names = TRUE)
dt <- data.table::as.data.table(all.files)
for(f in dt$all.files){
fs <- file.size(f)
dt[all.files == f, fSize_Mb := fs/projParams$bytesToMbytes]
}
message("Found ", nrow(dt))
return(dt)
}
```
# Introduction
This report forms part of the `[saveData](https://git.soton.ac.uk/SERG/saveData)` R package [@saveData] and acts as both a test report to list all the files in the UKDA SAVE data archive and also a template that can be adapted for other reporting on this data.
> NB: it will not run without the SAVE data [@saveUKDA] so you should [download it](xxx) before you start!
# Data files
## Documentation
```{r docsFiles}
p <- paste0(projParams$ukdaDataPath, "docs")
files <- getFileList(p)
if(nrow(files) > 0){
kableExtra::kable(files, caption = "Documentation files",
digits = 2) %>%
kable_styling(bootstrap_options = c("striped", "hover"))
}
```
## Survey data
```{r surveyFiles}
p <- paste0(projParams$ukdaDataPath, "survey")
files <- getFileList(p)
if(nrow(files) > 0){
kableExtra::kable(files, caption = "Survey data files",
digits = 2) %>%
kable_styling(bootstrap_options = c("striped", "hover"))
}
```
## Electricity consumption data
```{r consumptionFiles}
p <- paste0(projParams$ukdaDataPath, "consumption")
files <- getFileList(p)
if(nrow(files) > 0){
kableExtra::kable(files, caption = "Electricity consumption data files",
digits = 2) %>%
kable_styling(bootstrap_options = c("striped", "hover"))
}
```
# R environment
```{r check runtime, include=FALSE}
t <- proc.time() - startTime
elapsed <- t[[3]]
```
Analysis completed in `r round(elapsed,2)` seconds ( `r round(elapsed/60,2)` minutes) using [knitr](https://cran.r-project.org/package=knitr) [@knitr] in [RStudio](http://www.rstudio.com) with `r R.version.string` running on `r R.version$platform`.
## R packages
* base R [@baseR]
* bookdown [@bookdown]
* data.table [@data.table]
* here [@here]
* kableExtra [@kableExtra]
* knitr [@knitr]
* rmarkdown [@rmarkdown]
## Session info
```{r sessionInfo, echo=FALSE}
sessionInfo()
```
# References
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment