Discussion:
[hakyll] Hakyll + R
Corentin Dupont
2015-07-08 09:18:03 UTC
Permalink
Hi,
I created a small utility to integrate Rmd posts in Hakyll (pretty much a
work in progress now):
https://github.com/cdupont/hakyll-R

Basically it takes .Rmd files and produces a .md file together with a list
of figures (.png files) that are integrated inside the document.
My question is: how to inform Hakyll that those supplementary files are
created, to have them copied to the correct destination?
Should I use metaCompile?

Thanks,
Corentin
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Julien Tanguy
2015-07-08 09:35:45 UTC
Permalink
Hello,

This question is similar to this another thread [1] relative to graphviz
generation from source.

You have two paths:

- Either you inline the images as base64-encoded strings,
- You write a custom datatype which holds the contents of multiple
files, and write the corresponding `Writable` instance

I would guess that the first solution is easier to fit in the existing
hakyll.



Julien

[1]: https://groups.google.com/forum/#!msg/hakyll/hs8u4hhlsxI/3edGaijQPYoJ
Post by Corentin Dupont
Hi,
I created a small utility to integrate Rmd posts in Hakyll (pretty much a
https://github.com/cdupont/hakyll-R
Basically it takes .Rmd files and produces a .md file together with a list
of figures (.png files) that are integrated inside the document.
My question is: how to inform Hakyll that those supplementary files are
created, to have them copied to the correct destination?
Should I use metaCompile?
Thanks,
Corentin
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Corentin Dupont
2015-07-08 09:49:52 UTC
Permalink
I found this thread where it is advised to use metaCompile when several
files are produced:

https://groups.google.com/forum/#!topic/hakyll/vQpijNtTG5M

Regarding inlining images, I use Pandoc for the conversion .md -> .html. Is
there some arguments to give to Pandoc to have it inline images?
The full conversion is like that:

.Rmd ---R--> .md + figures ---pandoc--> .html


Another question: if a rule transforms a .Rmd into .md, and another one
transforms a .md into .html, will they be chained togheter to produce the
final html file from the .Rmd?

Thanks!
Post by Julien Tanguy
Hello,
This question is similar to this another thread [1] relative to graphviz
generation from source.
- Either you inline the images as base64-encoded strings,
- You write a custom datatype which holds the contents of multiple
files, and write the corresponding `Writable` instance
I would guess that the first solution is easier to fit in the existing
hakyll.
Julien
[1]: https://groups.google.com/forum/#!msg/hakyll/hs8u4hhlsxI/3edGaijQPYoJ
Post by Corentin Dupont
Hi,
I created a small utility to integrate Rmd posts in Hakyll (pretty much a
https://github.com/cdupont/hakyll-R
Basically it takes .Rmd files and produces a .md file together with a
list of figures (.png files) that are integrated inside the document.
My question is: how to inform Hakyll that those supplementary files are
created, to have them copied to the correct destination?
Should I use metaCompile?
Thanks,
Corentin
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Corentin Dupont
2015-07-08 14:05:03 UTC
Permalink
I'm trying with the Writable instance, but it does not seem to be easy...

What I would like is just to mention to Hakyll that my compiler generated
additional files, that just need to be copied as-is.
In fact, if the copy compiler runs after the Rmd compiler, it works.

Regarding inlining the file: I cannot find a solution with knit.
With Pandoc, there seem to be something: the option --self-contained
http://pandoc.org/README.html

There is this Pandoc module:
https://hackage.haskell.org/package/pandoc-1.9.3/docs/Text-Pandoc-SelfContained.html

Not sure how it should be used, though...
You may have to configure knitr to output inline base64 images instead of
separate files. I found this issue [1] on the official github repo, I hope
it solves your problem.
For your question, ragarding chaining rules, I'd guess it does, but I'm
not sure.
[1]: https://github.com/yihui/knitr/issues/944
Post by Corentin Dupont
I found this thread where it is advised to use metaCompile when several
https://groups.google.com/forum/#!topic/hakyll/vQpijNtTG5M
Regarding inlining images, I use Pandoc for the conversion .md -> .html.
Is there some arguments to give to Pandoc to have it inline images?
.Rmd ---R--> .md + figures ---pandoc--> .html
Another question: if a rule transforms a .Rmd into .md, and another one
transforms a .md into .html, will they be chained togheter to produce the
final html file from the .Rmd?
Thanks!
Post by Julien Tanguy
Hello,
This question is similar to this another thread [1] relative to graphviz
generation from source.
- Either you inline the images as base64-encoded strings,
- You write a custom datatype which holds the contents of multiple
files, and write the corresponding `Writable` instance
I would guess that the first solution is easier to fit in the existing
hakyll.
Julien
https://groups.google.com/forum/#!msg/hakyll/hs8u4hhlsxI/3edGaijQPYoJ
Post by Corentin Dupont
Hi,
I created a small utility to integrate Rmd posts in Hakyll (pretty much
https://github.com/cdupont/hakyll-R
Basically it takes .Rmd files and produces a .md file together with a
list of figures (.png files) that are integrated inside the document.
My question is: how to inform Hakyll that those supplementary files are
created, to have them copied to the correct destination?
Should I use metaCompile?
Thanks,
Corentin
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Corentin Dupont
2015-07-08 15:28:30 UTC
Permalink
I tried to write the Writable instance:
data RmdData = RmdData String [BS.ByteString]
deriving (Typeable, Generic)

instance Binary RmdData
instance Writable RmdData where
write path item = do
let (RmdData s fs) = itemBody item
writeFile path s
mapM_ writeFigure (zip fs [1..]) where
writeFigure (f, i) = BS.writeFile ((dropFileName path) ++ "plots-" ++
(show i) ++ ".png") f

pandocRmdCompiler :: Compiler (Item RmdData)
pandocRmdCompiler ropt wopt = ...


The problem is that now my pandocRmdCompiler is not compatible with the
rest of the compilers:

compile $ do
pandocRmdCompiler
Post by Corentin Dupont
= saveSnapshot "content"
= return . fmap demoteHeaders
= loadAndApplyTemplate "blog/templates/post.html"
(postCtx tags cats)
Post by Corentin Dupont
= loadAndApplyTemplate "blog/templates/mainperso.html"
(postCtx tags cats)
Post by Corentin Dupont
= relativizeUrls
I'm trying with the Writable instance, but it does not seem to be easy...
What I would like is just to mention to Hakyll that my compiler generated
additional files, that just need to be copied as-is.
In fact, if the copy compiler runs after the Rmd compiler, it works.
Regarding inlining the file: I cannot find a solution with knit.
With Pandoc, there seem to be something: the option --self-contained
http://pandoc.org/README.html
https://hackage.haskell.org/package/pandoc-1.9.3/docs/Text-Pandoc-SelfContained.html
Not sure how it should be used, though...
You may have to configure knitr to output inline base64 images instead of
separate files. I found this issue [1] on the official github repo, I hope
it solves your problem.
For your question, ragarding chaining rules, I'd guess it does, but I'm
not sure.
[1]: https://github.com/yihui/knitr/issues/944
Post by Corentin Dupont
I found this thread where it is advised to use metaCompile when several
https://groups.google.com/forum/#!topic/hakyll/vQpijNtTG5M
Regarding inlining images, I use Pandoc for the conversion .md -> .html.
Is there some arguments to give to Pandoc to have it inline images?
.Rmd ---R--> .md + figures ---pandoc--> .html
Another question: if a rule transforms a .Rmd into .md, and another one
transforms a .md into .html, will they be chained togheter to produce the
final html file from the .Rmd?
Thanks!
Post by Julien Tanguy
Hello,
This question is similar to this another thread [1] relative to
graphviz generation from source.
- Either you inline the images as base64-encoded strings,
- You write a custom datatype which holds the contents of multiple
files, and write the corresponding `Writable` instance
I would guess that the first solution is easier to fit in the existing
hakyll.
Julien
https://groups.google.com/forum/#!msg/hakyll/hs8u4hhlsxI/3edGaijQPYoJ
Post by Corentin Dupont
Hi,
I created a small utility to integrate Rmd posts in Hakyll (pretty
https://github.com/cdupont/hakyll-R
Basically it takes .Rmd files and produces a .md file together with a
list of figures (.png files) that are integrated inside the document.
My question is: how to inform Hakyll that those supplementary files
are created, to have them copied to the correct destination?
Should I use metaCompile?
Thanks,
Corentin
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Corentin Dupont
2015-07-09 15:13:22 UTC
Permalink
I finally solved the problem with Pandoc.SelfContained.

Package published!
https://hackage.haskell.org/package/hakyll-R
Post by Corentin Dupont
data RmdData = RmdData String [BS.ByteString]
deriving (Typeable, Generic)
instance Binary RmdData
instance Writable RmdData where
write path item = do
let (RmdData s fs) = itemBody item
writeFile path s
mapM_ writeFigure (zip fs [1..]) where
writeFigure (f, i) = BS.writeFile ((dropFileName path) ++ "plots-"
++ (show i) ++ ".png") f
pandocRmdCompiler :: Compiler (Item RmdData)
pandocRmdCompiler ropt wopt = ...
The problem is that now my pandocRmdCompiler is not compatible with the
compile $ do
pandocRmdCompiler
Post by Corentin Dupont
= saveSnapshot "content"
= return . fmap demoteHeaders
= loadAndApplyTemplate "blog/templates/post.html"
(postCtx tags cats)
Post by Corentin Dupont
= loadAndApplyTemplate "blog/templates/mainperso.html"
(postCtx tags cats)
Post by Corentin Dupont
= relativizeUrls
I'm trying with the Writable instance, but it does not seem to be easy...
What I would like is just to mention to Hakyll that my compiler generated
additional files, that just need to be copied as-is.
In fact, if the copy compiler runs after the Rmd compiler, it works.
Regarding inlining the file: I cannot find a solution with knit.
With Pandoc, there seem to be something: the option --self-contained
http://pandoc.org/README.html
https://hackage.haskell.org/package/pandoc-1.9.3/docs/Text-Pandoc-SelfContained.html
Not sure how it should be used, though...
You may have to configure knitr to output inline base64 images instead
of separate files. I found this issue [1] on the official github repo, I
hope it solves your problem.
For your question, ragarding chaining rules, I'd guess it does, but I'm
not sure.
[1]: https://github.com/yihui/knitr/issues/944
Post by Corentin Dupont
I found this thread where it is advised to use metaCompile when several
https://groups.google.com/forum/#!topic/hakyll/vQpijNtTG5M
Regarding inlining images, I use Pandoc for the conversion .md ->
.html. Is there some arguments to give to Pandoc to have it inline images?
.Rmd ---R--> .md + figures ---pandoc--> .html
Another question: if a rule transforms a .Rmd into .md, and another one
transforms a .md into .html, will they be chained togheter to produce the
final html file from the .Rmd?
Thanks!
Post by Julien Tanguy
Hello,
This question is similar to this another thread [1] relative to
graphviz generation from source.
- Either you inline the images as base64-encoded strings,
- You write a custom datatype which holds the contents of multiple
files, and write the corresponding `Writable` instance
I would guess that the first solution is easier to fit in the existing
hakyll.
Julien
https://groups.google.com/forum/#!msg/hakyll/hs8u4hhlsxI/3edGaijQPYoJ
Post by Corentin Dupont
Hi,
I created a small utility to integrate Rmd posts in Hakyll (pretty
https://github.com/cdupont/hakyll-R
Basically it takes .Rmd files and produces a .md file together with a
list of figures (.png files) that are integrated inside the document.
My question is: how to inform Hakyll that those supplementary files
are created, to have them copied to the correct destination?
Should I use metaCompile?
Thanks,
Corentin
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...