{"id":2095,"date":"2024-01-16T16:08:07","date_gmt":"2024-01-16T15:08:07","guid":{"rendered":"https:\/\/ada-sub.dh-index.org\/blog\/14034whichtowp\/"},"modified":"2024-01-24T08:56:27","modified_gmt":"2024-01-24T07:56:27","slug":"14034whichtowp","status":"publish","type":"post","link":"https:\/\/ada-sub.dh-index.org\/blog\/14034whichtowp\/","title":{"rendered":"A post from R"},"content":{"rendered":"<style>#knitxwp-2095 pre {  width: 100%;  overflow: scroll;  color:green;}<\/style>\n<div id=\"knitxwp-2095\">\n<div id=\"2095-top-1\">\n<style>.backtop a{font-size:24px;text-decoration:none;}<\/style>\n<\/div>\n<ul>\n<li><a href=\"#2095-pub-essai-r-to-wp\">1 pub essai R to WP<\/a>\n<ul>\n<li><a href=\"#2095-snc\">1.1 snc<\/a><\/li>\n<li><a href=\"#2095-workaround\">1.2 workaround<\/a><\/li>\n<li><a href=\"#2095-persistent-solution\">1.3 persistent solution<\/a><\/li>\n<li><a href=\"#2095-r-package\">1.4 R package<\/a><\/li>\n<li><a href=\"#2095-issues\">1.5 issues<\/a>\n<ul>\n<li><a href=\"#2095-section\">1.5.1 14045.<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#2095-versions\">1.6 versions<\/a>\n<ul>\n<li><a href=\"#2095-v0.1.5\">1.6.1 14037.v0.1.5<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#2095-b-references\">2 B: references<\/a><\/li>\n<\/ul>\n<h1 id=\"2095-pub-essai-r-to-wp\">1 pub essai R to WP<\/h1>\n<p>publishing using R package <em>duncantl\/RWordPress<\/em> (Lang 2023) wks half: the pandoc citation features and footnotes which are generated by the <em>knit2wp()<\/em>-function of the <em>knitr<\/em> package (Yihui 2024) are not correctly converted to the post html.<\/p>\n<h2 id=\"2095-snc\">1.1 snc <a class=\"backtop\" href=\"#2095-top-1\">\u21ea<\/a><\/h2>\n<ol>\n<li>knitXwp lib installed on mini.2:post wt lib,apply.css,uniquecss id,chk,toc,img1<\/li>\n<\/ol>\n<h2 id=\"2095-workaround\">1.2 workaround <a class=\"backtop\" href=\"#2095-top-1\">\u21ea<\/a><\/h2>\n<pre><code class=\"language-r\">library(markdown)\nlibrary(rmarkdown)\npid&lt;-0 # set postID of post created with knit2wp() or any existing post\nrmd&lt;-&quot;sample.Rmd&quot; # path of the R-Markdown file\nwp.knit.post&lt;-function(rmd,pid){\nrender(rmd) # renders the .Rmd according to the parameters specified in the YAML header of the .Rmd\nmd.ns&lt;-gsub(&quot;\\\\.Rmd&quot;,&quot;.md&quot;,rmd)\np.content&lt;-readLines(md.ns)\np.html&lt;-mark(p.content) # renders the created .md file\neditPost(pid,content = p.html) # actualises post content\n}\n<\/code><\/pre>\n<p>script to create html content of post<\/p>\n<pre><code>---\ntitle: &quot;14022&quot;\nauthor: &quot;xxx&quot;\ndate: &quot;2024-01-08&quot;\noutput: \n  md_document:\n   variant: markdown_phpextra+backtick_code_blocks\n   toc: true\n   number_sections: true\n   pandoc_args: [&quot;--wrap=none&quot;]\nbibliography: sample.bib\n---\n<\/code><\/pre>\n<p>yaml-header of the .Rmd rendered<\/p>\n<h2 id=\"2095-persistent-solution\">1.3 persistent solution <a class=\"backtop\" href=\"#2095-top-1\">\u21ea<\/a><\/h2>\n<p>modified the content of the <em>knit2wp()<\/em> function as to use <em>render()<\/em> and <em>mark()<\/em> instead of <em>knit()<\/em> and <em>markdownToHTML()<\/em>. now works.<\/p>\n<h2 id=\"2095-r-package\">1.4 R package <a class=\"backtop\" href=\"#2095-top-1\">\u21ea<\/a><\/h2>\n<p>wrote small R package that does the same: <a href=\"https:\/\/github.com\/esteeschwarz\/knitXwp\">https:\/\/github.com\/esteeschwarz\/knitXwp<\/a><\/p>\n<h2 id=\"2095-issues\">1.5 issues <a class=\"backtop\" href=\"#2095-top-1\">\u21ea<\/a><\/h2>\n<h3 id=\"2095-section\">1.5.1 14045. <a class=\"backtop\" href=\"#2095-top-1\">\u21ea<\/a><\/h3>\n<ul>\n<li>if there are images in the post: they are uploaded, but not overwritten on the server, if uploaded again in case you actualise the post. that means for every post action a new image on the server is created with a trailing increasing number. this is a wordpress feature to prevent overwrite uploaded files with the same name.<\/li>\n<li>tweaking in the wordpress functions to prevent that, had no success. so i will integrate a function which allows deleting old instances of images if you decide for that.<\/li>\n<\/ul>\n<h4 id=\"2095-play-along-image-references\">1.5.1.1 play along image references <a class=\"backtop\" href=\"#2095-top-1\">\u21ea<\/a><\/h4>\n<figure>\n<img decoding=\"async\" src=\"https:\/\/ada-sub.dh-index.org\/blog\/wp-content\/uploads\/wp001-fig-01-wordcloud-1-3.png\" alt=\"quanteda wordcloud output of this document\" \/><figcaption aria-hidden=\"true\">quanteda wordcloud output of this document<\/figcaption><\/figure>\n<h2 id=\"2095-versions\">1.6 versions <a class=\"backtop\" href=\"#2095-top-1\">\u21ea<\/a><\/h2>\n<h3 id=\"2095-v0.1.5\">1.6.1 14037.v0.1.5 <a class=\"backtop\" href=\"#2095-top-1\">\u21ea<\/a><\/h3>\n<ul>\n<li>its now possible to apply a stylesheet to the html output of the post container in the blog.<\/li>\n<li>prevent toc entry jumping across different post with possible same toc entries (references, method), added unique id to all section headers and toc entries<\/li>\n<li>add back-to-top button to section headers to jump back to outline from there<\/li>\n<\/ul>\n<hr \/>\n<h1 id=\"2095-b-references\">2 B: references <a class=\"backtop\" href=\"#2095-top-1\">\u21ea<\/a><\/h1>\n<div id=\"refs\" class=\"references csl-bib-body hanging-indent\" markdown=\"1\">\n<div id=\"ref-lang_duncantlrwordpress_2023\" class=\"csl-entry\" markdown=\"1\">\n<p>Lang, Duncan Temple. 2023. \u201cDuncantl\/RWordPress.\u201d <a href=\"https:\/\/github.com\/duncantl\/RWordPress\">https:\/\/github.com\/duncantl\/RWordPress<\/a>.<\/p>\n<\/div>\n<div id=\"ref-yihui_knitr_2024\" class=\"csl-entry\" markdown=\"1\">\n<p>Yihui, Xie. 2024. \u201cKnitr &#8211; Yihui Xie \u8c22\u76ca\u8f89.\u201d <a href=\"https:\/\/yihui.org\/knitr\/\">https:\/\/yihui.org\/knitr\/<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1 pub essai R to WP 1.1 snc 1.2 workaround 1.3 persistent solution 1.4 R package 1.5 issues 1.5.1 14045. 1.6 versions 1.6.1 14037.v0.1.5 2 B: references 1 pub essai R to WP publishing using R package duncantl\/RWordPress (Lang 2023) wks half: the pandoc citation features and footnotes which are generated by the knit2wp()-function of &hellip; <a href=\"https:\/\/ada-sub.dh-index.org\/blog\/14034whichtowp\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;A post from R&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_lmt_disableupdate":"","_lmt_disable":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[55,50],"tags":[91,90,92,72,68],"class_list":["post-2095","post","type-post","status-publish","format-standard","hentry","category-rr","category-snc","tag-cf","tag-chkpng","tag-img","tag-package","tag-snc"],"acf":[],"modified_by":null,"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ada-sub.dh-index.org\/blog\/wp-json\/wp\/v2\/posts\/2095","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ada-sub.dh-index.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ada-sub.dh-index.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ada-sub.dh-index.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ada-sub.dh-index.org\/blog\/wp-json\/wp\/v2\/comments?post=2095"}],"version-history":[{"count":25,"href":"https:\/\/ada-sub.dh-index.org\/blog\/wp-json\/wp\/v2\/posts\/2095\/revisions"}],"predecessor-version":[{"id":2232,"href":"https:\/\/ada-sub.dh-index.org\/blog\/wp-json\/wp\/v2\/posts\/2095\/revisions\/2232"}],"wp:attachment":[{"href":"https:\/\/ada-sub.dh-index.org\/blog\/wp-json\/wp\/v2\/media?parent=2095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ada-sub.dh-index.org\/blog\/wp-json\/wp\/v2\/categories?post=2095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ada-sub.dh-index.org\/blog\/wp-json\/wp\/v2\/tags?post=2095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}