KnitR
KnitR is package for the RStudio, which allows to produce word processing documents, PDF, presentations,... with real-time embedding of data. E.g. current stock exchange rates can fetched, analyse within R and dependent on the analysis phrases and results can be inject e.g. in the text. The package KnitR is often used within RStudio as a graphical user interface for calling commands and scripts for the underlying statistic software R (see Wikipedia:Knitr for details).
From the command line up to date reports can be generated automatically by processing a R-Markdown document and at processing time the current data sources (e.g. monitoring data) is evaluated in the statistical or numerical analysis.
If learners are able to see the R-Code in the learning document they can perform activities in the software for statistics on their own. Furthermore for research publications in the Wikiversity[1] readers can
- reproduce the results,
- learn from the methodology,
- apply the R-code on their own data,
- check if the algorithm are appropriate for experimental design
Learning Modules
[edit | edit source]- Understand the basic workflow of KnitR
- Installation of KnitR
- Standard Pitfalls and the solutions
- Compilation of Output
- Use Octave in KnitR
- Hello World Example
- Sample Data
- Fetching Data from an API
- Use KnitR
- External Code Chunk
- Future: KnitR-Integration/-Inteface for Wikiversity or a WikiJournal
Technical Tasks for Learners
[edit | edit source]- (Installation) Install RStudio and the package KnitR and create and process your first KnitR-document.
- (Octave in KnitR) Analyse the possibility to integrate the calculations with Octave in a KnitR markdown document.
Learning Task
[edit | edit source]In the previous section the workflow of a integrated approach of KnitR was elaborated. Due to the fact that this concept is not implemented yet as extension in MediaWiki yet, the workflow cannot performed with code chunk for mathematical calculations in the MediaWiki of Wikiversity directly. But it possible to learn about the workflow in general:
- Install R-Studio and R on your computer.
- Install the KnitR-Package in R-Studio.
- Download Sample Data e.g. R Sample Data by Guru99[2]
- Learn about KnitR with Screencasts (Youtube) and perform a basic KnitR tutorial so that you get the first dynamic report.
- Video - Learn Knitr in 5min (Youtube) by Ram Narasimhan - retrieved 2016/10/11
- Video - Professional Report Writing with Sweave, LaTeX, and R (Youtube) by Nicolas Yager - retrieved 2016/10/11
- knitr: Automatically embedding R output in documents (Youtube) by Joshua Wiley 2013/10/14
- Advanced Learners/Spatial Analysis: Apply a scenario in the Risk Management Module for creating Risk Maps. What are additional requirements for the spatial analysis?
- learn about the design of Geographic Information Systems (GIS) (Classification Resource by Dave Braunschweig),
- install Open Source Quantum GIS[3] and explore the QGIS manual and try to match the general element of GIS with features offered in QGIS manual (Furthermore explore QGIS ScreenCasts on Youtube according to level of expertise in GIS).
- extract data from GIS database process spatial data with R-script,
- integrate generated maps and calculated R results in the KnitR document (Spatial Analysis with R Youtube published by Domino Data Lab 2016/02).
- (Jupyter) Analyse the Open Source framework Jupyter and analyse the difference and similarities between KnitR and Jupyter. When will you use KnitR and when would you use Jupyter.
- Analyse the COVID-19 outbreak and the requirements of dynamic updates in 2020. What are the requirements and constraints to create a dynamic report mechanism based on KnitR and R for the COVID-19 epidemics.
- Explore the concept of Scientific Hackathon and explain why KnitR can be used as a development environment for decision support products!
- (KnitR Templates) Create a KnitR template that loads input data from a dataset
input.csv
calls aprocess_data(...)
function and creates anoutput.csv
for processed data. Include some of source data and aggregated source data in the R-Markdown.
Some external knitR tutorials
[edit | edit source]- Rstudio, an IDE to create knitR documents, containts also simple examples
- Karl Broman's minimal tutorial discusses the very basics of knitR, a very good point to get you started
- The knitR homepage does not only contain the source, but also some links and examples
- An introductional video on YouTube, which illustrates the generation of a knitR document using RStudio
- A nice short video to get you started in only five minutes
Wiki to Markdown Conversion with PanDoc
[edit | edit source]The OpenSource tool PanDoc is called the "swiss army knife" of document conversion. Assume we have a KnitR document of a scientific paper that contains the KnitR code chunks for processing the data, that was analysed.
- converted the Markdown document of the paper with PanDoc-Online Converter in a MediaWiki document.
- Create a sample document with the knitr-package in RStudio and save the R-Markdown file with the extension Rmd to your harddrive.
- Copy the content of your R-Markdown document to PanDoc-Online Converter,
- select Markdown (pandoc) as input format,
- select MediaWiki as output format,
- press Convert-button and analyze the generated MediaWiki syntax of the text.
- The R-Code chunks for the analysis of the data (e.g. loaded from CSV file of spreadsheet document) is converted into a <code>-environment.
- This converted KnitR document is stored together with the scientific papers in the WikiJournal (e.g. WikiJournal of Medicine). If sampling of data was performed in the same way the application of the KnitR-document with the new data will be performed in the same algorithmic way. This KnitR-approach contributes to a workflow for Reproducible Science.
See also
[edit | edit source]- The R Programming wikibook
- PanDocElectron converter for documents
- Educational Content Sink
- Reproducibility
- Dynamic Document Generation
- HTML5 Processing of MediaWiki Markdown Acticles - First milestone - access to MediaWiki source text in a HTML document with Javascript - example shows download of Wikiversity:Swarm Intelligence in a textarea of a HTML file.
- Scientific Hackathon
- Open Community Approach
- Open Source Science
- COVID-19/Mathematical Modelling - Use case for dynamic reporting during an epidemiological spread.
References
[edit | edit source]- ↑ WikiJournal of Medicine - An open access journal with no publication costs – About ISSN: 2002-4436 www.WikiJMed.org Frequency: Continuous Since: March 2014 Publisher: Wikimedia Foundation
- ↑ guru99-edu Github User (2019) R-Programming respository with R sample data in CSV format for learning R - URL: https://github.com/guru99-edu/R-Programming - retrieved 2024/05/06
- ↑ Quantum Geographic Information System (QGIS) - Open Source Software Package for Linux, Windows, Mac (2017) - LTR 2.18.11 access 2017/08/14 - https://www.qgis.org/en/site/forusers/download.html
External links
[edit | edit source]- KnitR Official website
- Repository on GitHub
- Example code on GitHub
- knitr package on CRAN
- R Statistics and R Studio as Graphical User Interface for R.
- Video - Learn Knitr in 5min (Youtube) by Ram Narasimhan - retrieved 2016/10/11
- Video - Professional Report Writing with Sweave, LaTeX, and R (Youtube) by Nicolas Yager - retrieved 2016/10/11
- knitr: Automatically embedding R output in documents by Joshua Wiley 2013/10/14
- PanDocElectron/How to create a html presentation
- Wikipedia:Pandoc to create MarkDown input for KnitR
- PanDocElectron Installation Guide for Linux Windows and Mac (Linux is supported currently with binaries for Ubuntu/Mint/Debian only)
- Online Demo for Pandoc for plain text documents to create MarkDown input for KnitR from other formats
- Pandoc Official Website Support for document converter
- JuPyter - Similar concepts of KnitR-package in R with python interface.