Skip to content

Commit

Permalink
1st version
Browse files Browse the repository at this point in the history
  • Loading branch information
yannrichet committed Apr 28, 2022
0 parents commit ba8f5c0
Show file tree
Hide file tree
Showing 15 changed files with 777 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/ant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Java CI

on:
push:
branches: [ master ]
tags: [ 'v*.*' ]
pull_request:
branches: [ master ]

jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
java: [ 8 ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
java-package: jdk
- run: |
WD=$PWD
cd ..
git clone https://github.com/Funz/funz-profile
cd $WD
shell: bash
- run: ant -noinput -buildfile build.xml test

release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 1.8
java-package: jdk
- run: |
WD=$PWD
cd ..
git clone https://github.com/Funz/funz-profile
cd $WD
- run: |
ant clean dist
cd dist; zip -r ../plugin-Rmd.zip *; cd ..
ant install
zip -r Funz-Rmd.zip Funz-Rmd
- uses: actions/upload-artifact@v2
with:
path: dist
- uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: ./*-Rmd.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}



21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**/*-private
/**/log.txt
/**/*history

/build/
/tmp/
/nbproject/
/dist/
/test/

/*.png
/*.html
/*.log
/*.zip
/*.out
/*.csv
/*.txt
/*.Rout
/*.Rdata
/*.Rmd
/*.exec
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[![.github/workflows/ant.yml](https://github.com/Funz/plugin-Rmd/actions/workflows/ant.yml/badge.svg)](https://github.com/Funz/plugin-Rmd/actions/workflows/ant.yml)

# Funz plugin: Rmd

This plugin is dedicated to launch RMarkDown rendering from Funz.
It supports the following syntax and features:

* Input
* file type supported: *.Rmd, any other format for resources
* parameter syntax:
* variable syntax: `?[...]`
* formula syntax: `!{...}`
* comment char: `/`
* example input file:
```
---
title: "Untitled"
---
we set x1 to ?[x1~[1,2]]
we set x2 to ?x2
mean_speed=`r mean(cars$speed) + !{?x2 + 1.23 | #.###}`
```
* will identify input:
* x1, expected to vary inside [1,2]
* x2, expected to vary inside [0,1] (by default)
* replace `!{?x2 + 1.23 | #.###}` expression by its evaluation

* Output
* file type supported: *.html
* read any named value printed with '=`r ...', like
* example output file:
```
...
<p>mean_speed=15.4</p>
...
```
* will return output:
* mean_speed=15.4



![Analytics](https://ga-beacon.appspot.com/UA-109580-20/plugin-Rmd)
18 changes: 18 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<project name="plugin-Rmd" default="test" basedir=".">

<property name="code.name" value="Rmd" />
<property name="install.dir" value="${basedir}/Funz-${code.name}" />

<property name="build_plugin.xml" location="../funz-profile/build_plugin.xml" />
<import file="${build_plugin.xml}"/>

<target name="dist" depends="dist-ioplugin"/> <!-- dist-ioplugin: copy just the plugin ascii files -->

<target name="test" depends="test-ioplugin"/> <!-- test-ioplugin: test the plugin ascii files -->

<target name="install" depends="install-plugin"/> <!-- test-ioplugin: test the plugin ascii files -->

<target name="super.clean" depends="clean"/>
<target name="super.run-reference-cases" depends="run-reference-cases"/>

</project>
11 changes: 11 additions & 0 deletions src/main/io/Rmd.ioplugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variableStartSymbol=?
variableLimit=[...]
formulaStartSymbol=!
formulaLimit={...}
commentLineChar=#

datasetFilter=contains("(.*)","cat\\(") & contains("(.*)","---")

outputlist=`grep("(.*)Rmd","^(.*)=.r\\s")>>before("=")`

output.???.get=lines("(.*)html") >> filter("^<p>???=(.*)</p>$") >> after("=") >> before("<")
36 changes: 36 additions & 0 deletions src/main/samples/Untitled.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: "Untitled"
author: "IRSN / Y. Richet"
date: '2022-04-28'
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.

## Results

Funz parse Rmd numerical output using the syntax of inline Rmd on a new line:

mean_speed=`r mean(cars$speed)`
28 changes: 28 additions & 0 deletions src/main/scripts/Rmd.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@echo off

set PATH=%PATH%;C:\Program Files\R\R-4.1.0\bin

set id=%RANDOM%
start "Rmd_%id%" cmd /c "Rscript.exe -e ""rmarkdown::render('%1', output_format = 'html_document',output_file = '%1.html', encoding='UTF-8')"" > Rmd.Rout"
set PID_R="none"
for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "WINDOWTITLE eq Rmd_%id%"') do set PID_R=%%b
echo %PID_R% > PID

if "%PID_R%" neq "none" (
:loop
tasklist | findstr " %PID_R% " >nul
if not errorlevel 1 (
timeout /t 1 >nul
goto :loop
)
)

del /f PID

if not exist "*.Rout" (
exit 2
)
findstr "Err" *.Rout
if not errorlevel 1 (
exit 1
)
15 changes: 15 additions & 0 deletions src/main/scripts/Rmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

Rscript -e "rmarkdown::render('$1', output_format = 'html_document',output_file = '$1.html', encoding='UTF-8')" > Rmd.Rout &
PID_R=$!
echo $PID_R >> PID #this will allow Funz to kill process if needed

wait $PID_R

rm -f PID

ERROR=`tail -2 *.Rout | grep "Err"`
if [ ! "$ERROR" == "" ]; then
echo $ERROR >&2
exit 1
fi
11 changes: 11 additions & 0 deletions src/test/cases/Untitled.Rmd/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#Thu Apr 28 18:43:15 CEST 2022
duration=0
output={mean_speed\=15.4}
output.mean_speed=15.4
code=Rmd
input.No\ name=No value
start=18\:43\:14
end=
state=running
calc=localhost\:41909
info=Results parsed\: {1\=1.0, mean_speed\=15.4}
36 changes: 36 additions & 0 deletions src/test/cases/Untitled.Rmd/input/Untitled.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: "Untitled"
author: "IRSN / Y. Richet"
date: '2022-04-28'
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.

## Results

Funz parse Rmd numerical output using the syntax of inline Rmd on a new line:

mean_speed=`r mean(cars$speed)`
26 changes: 26 additions & 0 deletions src/test/cases/Untitled.Rmd/output/Rmd.Rout
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
| | | 0% | |.......... | 14%
ordinary text without R code

| |.................... | 29%
label: setup (with options)
List of 1
$ include: logi FALSE

| |.............................. | 43%
ordinary text without R code

| |........................................ | 57%
label: cars
| |.................................................. | 71%
ordinary text without R code

| |............................................................ | 86%
label: pressure (with options)
List of 1
$ echo: logi FALSE

| |......................................................................| 100%
inline R code fragments


/usr/bin/pandoc +RTS -K512m -RTS Untitled.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output Untitled.Rmd.html --lua-filter /home/richet/R/x86_64-pc-linux-gnu-library/4.1/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /home/richet/R/x86_64-pc-linux-gnu-library/4.1/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --variable bs3=TRUE --standalone --section-divs --template /home/richet/R/x86_64-pc-linux-gnu-library/4.1/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable theme=bootstrap --include-in-header /tmp/Rtmp8CSktq/rmarkdown-str23b5e49732e42.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
Expand Down
36 changes: 36 additions & 0 deletions src/test/cases/Untitled.Rmd/output/Untitled.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: "Untitled"
author: "IRSN / Y. Richet"
date: '2022-04-28'
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.

## Results

Funz parse Rmd numerical output using the syntax of inline Rmd on a new line:

mean_speed=`r mean(cars$speed)`
430 changes: 430 additions & 0 deletions src/test/cases/Untitled.Rmd/output/Untitled.Rmd.html

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/test/cases/Untitled.Rmd/output/err.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


processing file: Untitled.Rmd
output file: Untitled.knit.md


Output created: Untitled.Rmd.html
Empty file.

0 comments on commit ba8f5c0

Please sign in to comment.