Skip to content

Commit ed6dd96

Browse files
committed
Add the documentation generation scripts
1 parent 079a2eb commit ed6dd96

File tree

10 files changed

+1186
-3941
lines changed

10 files changed

+1186
-3941
lines changed

R_example.ipynb

Lines changed: 0 additions & 3309 deletions
This file was deleted.

_pkgdown.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
destination: docs
2+
3+
home:
4+
title: UpSet (Venn diagrams alternative) plots extensible with ggplot2 geoms
5+
description: Get all the goodies of UpSet, but with full extensibility of ggplot2
6+
7+
template:
8+
opengraph:
9+
twitter:
10+
creator: "@krassowski"
11+
card: summary_large_image
12+

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ pandas
22
pydataset
33
jupyterlab
44
rpy2
5-
scikit_learn

scripts/compile_examples.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
echo "Compiling Python examples"
4+
../scripts/expand_run_magic.py Examples.ipynb Examples_Python.ipynb
5+
jupyter nbconvert --execute --to notebook --inplace Examples_Python.ipynb
6+
echo "Compiling R examples"
7+
../scripts/translate_examples.py Examples.ipynb _R_Examples.ipynb
8+
../scripts/expand_run_magic.py _R_Examples.ipynb Examples_R.ipynb
9+
jupyter nbconvert --execute --to notebook --inplace Examples_R.ipynb
10+
echo "Done"

scripts/document.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
Rscript -e 'devtools::document()'
4+
cd vignettes
5+
../scripts/compile_examples.sh
6+
cd ..
7+
for v in Examples_Python Examples_R
8+
do
9+
jupyter nbconvert --to markdown "vignettes/${v}.ipynb"
10+
mv "vignettes/${v}.md" "vignettes/${v}.Rmd"
11+
sed 's/```r/```{r eval=FALSE}/g' "vignettes/${v}.Rmd" -i
12+
sed 's/```python/```{python eval=FALSE}/g' "vignettes/${v}.Rmd" -i
13+
sed 's/\[png\]/[ ]/g' "vignettes/${v}.Rmd" -i
14+
sed -i "1s/^/---\ntitle: \"${v}\"\n---\n/" "vignettes/${v}.Rmd"
15+
done
16+
Rscript -e 'pkgdown::build_site()'

scripts/expand_run_magic.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import json
4+
5+
input_path = sys.argv[1]
6+
output_path = sys.argv[2]
7+
8+
exapnded = 0
9+
10+
with open(input_path) as f:
11+
nb_in = json.load(f)
12+
13+
new_cells = []
14+
15+
for cell in nb_in['cells']:
16+
if cell['cell_type'] != 'code':
17+
new_cells.append(cell)
18+
continue
19+
code = ''.join(cell['source'])
20+
if code.startswith('%run'):
21+
to_include = code[5:].strip()
22+
with open(to_include) as o:
23+
nb_run = json.load(o)
24+
new_cells.extend(nb_run['cells'])
25+
expanded = 1
26+
else:
27+
new_cells.append(cell)
28+
29+
assert expanded
30+
print(f'Expanded {expanded} run magics')
31+
32+
with open(output_path, 'w') as f:
33+
nb_in['cells'] = new_cells
34+
json.dump(nb_in, f)
35+
36+
print(f'Saved as {output_path}')

scripts/translate_examples.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import json
4+
import re
5+
6+
python_input_path = sys.argv[1]
7+
r_output_path = sys.argv[2]
8+
9+
prepare_changed = False
10+
11+
print(f'Will translate Python exampels from {python_input_path} into R examples')
12+
13+
with open(python_input_path) as f:
14+
nb_in = json.load(f)
15+
16+
new_cells = []
17+
18+
for cell in nb_in['cells']:
19+
if cell['cell_type'] == 'code':
20+
first = cell['source'][0].strip()
21+
#code = ''.join(cell['source'])
22+
if first.strip() == '%run Prepare_Python.ipynb':
23+
cell['source'] = [
24+
'%run Prepare_R.ipynb'
25+
]
26+
prepare_changed = True
27+
elif first.startswith('%%R'):
28+
first = first[4:].strip()
29+
if first:
30+
args = first.split(' ')
31+
args = {
32+
args[i*2]: args[i*2 + 1]
33+
for i in range(len(args)//2)
34+
}
35+
assert args
36+
w = int(args["-w"]) / 100
37+
h = int(args["-h"]) / 100
38+
if round(w) == w:
39+
w = int(w)
40+
else:
41+
w = f'{w:.1f}'
42+
if round(h) == h:
43+
h = int(h)
44+
else:
45+
h = f'{h:.1f}'
46+
first = f'set_size({w}, {h})\n'
47+
cell['source'][0] = first
48+
elif first.startswith('%R'):
49+
first = first[2:].strip()
50+
cell['source'][0] = first
51+
new_cells.append(cell)
52+
53+
assert prepare_changed
54+
55+
with open(r_output_path, 'w') as f:
56+
nb_in['metadata'] = {
57+
"kernelspec": {
58+
"display_name": "R",
59+
"language": "R",
60+
"name": "ir"
61+
},
62+
"language_info": {
63+
"codemirror_mode": "r",
64+
"file_extension": ".r",
65+
"mimetype": "text/x-r-source",
66+
"name": "R",
67+
"pygments_lexer": "r",
68+
"version": "3.6.1"
69+
}
70+
}
71+
nb_in['cells'] = new_cells
72+
json.dump(nb_in, f)
73+
74+
print(f'Saved as {r_output_path}')

0 commit comments

Comments
 (0)