Julia DataFrames format in pdf with nbconvert - julia

How can I get a DataFrame in a Julia Notebook to output to a pdf with nbconvert and control the formatting like with knitr::kable or pander tables in an R-markdown document?
Julia notebook:
the following code cell
using DataFrames
A = DataFrame(randn(10, 7))
the pdf from nbconvert shows 10Œ7 DataFrames.DataFrame followed by an un-formatted table. Although display(A) and print(A) show different outputs in the notebook, the pdf from nbconvert shows the same output as the code cell above does in the notebook.
With the Python Markdown Notebook Extension, the following markdown cells display the table in the notebook, but in the nbconvert generated pdf, the DataFrame turns into a one dimensional array.
Test1
{{A}}
Test2
| |
|------|
|{{A}}|
How can I get output like kable or pander tables in a knitted R-markdown doc in a pdf from a Julia Notebook with nbconvert?
Also on Github.

From Github discussion, nbconvert cannot read the Markdown Notebook Extension html output. Tables should be output from code cells so nbconvert can output them to TeX -> pdf.
The next follow-on question about which Julia functions can do this best is on StackOverflow

Related

Compile Bookdown to Markdown?

Is there any way to take a Bookdown project, and build it as Markdown instead of HTML or TeX?
I ask because I need to post-process the final Markdown output from Bookdown, in order to extract R and Python notebooks for download.
In more detail, I am using Bookdown to build a textbook that embeds notebooks to download, where the notebooks contain subsets of the code and text in the bookdown .Rmd files. For example, a single chapter could contain more than one notebook.
In order to do this, I put start and end comment markers in the RMarkdown input text to identify the section that will be a notebook, and then post-process the generated Markdown files to extract the notebook section. As in something like:
<!--- notebook: first_section.Rmd
-->
Some explanation, maybe using Bookdown extra markup such as #a_citation.
```{r}
a <- 1
a
```
<!--- end of notebook
-->
More markdown.
```{r}
# More code not in notebook.
b <- 2
```
Obviously I could use the input RMarkdown pages, but this would be ugly, because all the extended Bookdown markup such as citations, cross-references and so on, would appear in raw and ugly form in the generated notebook. So I'd really like to be able to get the final output Markdown, after merging, resolving of citations and cross references. Is there any way of doing that?
My question is similar to this as-yet unanswered question, but adds my motivation for an official solution to this problem.
With the latest version of bookdown on CRAN, you can use the output format bookdown::markdown_document2, e.g.,
output:
bookdown::markdown_document2:
base_format: rmarkdown::md_document
variant: gfm

How can I convert a Rmd document to a jupyter notebook

I would like to convert a rmarkdown .Rmd document to a jupyter notebook .ipynb.
I found that converting from jupyter to rmd is easy using as described in reference page but for some reason (...) the Rstudio team did not do the other way.
For instance I would like to convert
---
title: "Untitled"
author: "statquant"
date: "03/09/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
After checking, the silver bullet seems to be jupytext
It allows you to convert from or to markdown, rmarkdown, python, ipynb, etc.
This can actually allow you a pretty neat workflow
write a simple R script, script.R, that you can spin into a Rmd document
use knitr::spin('script.R', knit = FALSE) to transform it to Rmd
use jupytext --to notebook script.Rmd to create script.ipynb
share or execute the notebook
sos-rmarkdown provides yet another Rmarkdown to Jupyter notebook converter. The unique features include its support for inline expressions using markdown-kernel, use of multiple kernels in one notebook (using a SoS kernel) to accommodate code blocks in multiple languages, and the ability to execute generated notebook using sos-papermill. It also uses cell meta data to control the display of input and output of code blocks in Jupyter Lab and exported HTML reports.
To use this tool, you can install sos-rmarkdown from pip or conda-forge, then run the converter with command
sos convert input.Rmd output.ipynb
or use option --execute to execute the converted notebook
sos convert input.Rmd output.ipynb --execute
Disclaimer: I am the author of sos-rmarkdown.
Here is another way.
The detailed answer (to convert .rmd to .ipynb) is described here: https://gist.github.com/ramnathv/10012123
TL;DR
Use a 3rd-party Python package notedown with sed command as follows:
1) Install a 3rd-party python package which does the conversion for us
$ pip install notedown
2) Use the installed package to convert from your *.Rmd file (or *.md) to *.ipynb and run the terminal command:
$ notedown example.Rmd | sed '/%%r/d' > example.ipynb

Word to R Markdown Conversion

I have received a file stored in Microsoft Word that includes formatted words (italics, bold). I would like to do some work with the file (extracting sections, inserting words, etc.) and was planning to do this work with R Markdown. I need to keep the formatting (italics, bold) from Word during this conversion. I know I can convert from Markdown to Word, but is the reverse conversion from Word to Markdown also possible? If not, does anyone have any suggestions of how to bring Word into Markdown (relatively) painlessly while maintaining the italics and bold formatting?
From the pandoc manual under "Demos": pandoc -s example30.docx -t markdown -o example35.md
For rmarkdown, please see this answer, Convert docx to Rmarkdown
You could use first pandoc, then RStudio.
In pandoc, pandoc -o output.md originFile.docx. In which, your
output is a markdown from a Word.
Open your RStudio, you can choose your type file at the bottom of the console, whether you select "markdown" or "Rmarkdown". You will be able to change your markdown file.
Also there is Writeage, from convert markdown to word. This is a pulgin in Word

xtable into RStudio in order to get Latex table format

I'm doing a LaTex document using RStudio in Windows 7 by using knitr. I've have some problems such as:
When I use xtable() for these data frames , I just can get the code for Latex, is it possible to get directly the Latex format of tables in my pdf?

Creating a title and numbering of sections on pdf while using R markdown with pandoc

I am using the markdown document created by R and I am trying to create the pdf file from the markdown using pandoc. Everything else works fine but I want the title of the document to appear and the numbering on the sections as in default Latex document. It seems the title defined on rmarkdown appears as a section title for the pdf.
I was able to create double spacing, enter line numbers etc by using a options.sty file. Below is the code that I used to create a pdf.
For options.sty I used:
\usepackage{setspace}
\doublespacing
\usepackage[vmargin=0.75in,hmargin=1in]{geometry}
\usepackage{lineno}
\usepackage{titlesec}
\titleformat{\section}
{\color{red}\normalfont\Large\bfseries}
{\color{red}\thesection}{1em}{}
\titleformat{\subsection}
{\color{blue}\normalfont\Large\bfseries}
{\color{blue}\thesection}{0.8em}{}
\title{Monitoring Stations}
\author{Jdbaba}
I used knitr to create the R markdown file. In the above options.sty file, it seems the program is not taking title and author part. It seems I am missing something.
The code I used to convert markdown to pdf is as follows:
pandoc -H options.sty mydata.md -o mydata.pdf
In latex document, the pdf would have the automatic numbering as well. But my pdf is missing that. Can anyone suggest how numbering can be enabled on the pdf document created using pandoc ?
Thanks.
Pandoc takes the title from a title block in the Markdown file. This is a Pandoc-specific extension to Markdown. The block should have the following format:
% title
% author(s) (separated by semicolons)
% date
So, in your case:
% Monitoring Stations
% Jdbaba
% March 6, 2013
To have the sections numbered, you'll need to run Pandoc with the --number-sections option.

Resources