I am trying to knit a table created by kable() and produce a Word document. When I knit using the RStudio knit button, it works fine and produces a formatted table. When I use render(), it does not. It produces just a unformatted string of text. Here is a minimal example:
test.Rmd
---
title: "Test"
output:
word_document:
keep_md: true
---
```{r pressure2, echo=FALSE}
knitr::kable(mtcars)
```
The render() command is
rmarkdown::render("test.Rmd", clean=FALSE)
The pandoc command that is run by both the Knit button (RStudio) and the render() command is
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to docx --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.docx --smart --highlight-style tango
I can see the problem in the test.utf8.md file produced by pandoc() when I run render(). The test.utf8.md file is an html table. I cannot see the test.utf8.md file produced by clicking the Knit button since that is not saved with keep_md=true. Only the test.md file is kept.
The RStudio Knit button must be changing the kable() format when output is word_document. If I change the kable() call to
knitr::kable(mtcars, format="markdown")
It works. The following sets the kable() format. I don't know what output format the user will select, so don't want to set format in the function call. Putting this with an if statement to detect if the output type is Word, fixes the problem.
options(knitr.table.format = 'markdown')
Related
First, I have installed the following packages in R-Markdown file
install.packages("tidyverse")
install.packages("ggplot2")
library(tidyverse)
library(ggplot2)
When I try to Knit to HTML or Word, I got this error-
*
Error in contrib.url(repos, "source") : trying to use CRAN without setting a mirror calls:... withvisible->eval->eval->install.packages->contrib.url
Execution halted*
Your help is appreciated in advance. Thank you
#ViviG where do I have to put this {r eval=FALSE}?
This is my current query:
Visualization
You can also embed the visualization, for example:
install.packages("tidyverse")
install.packages("ggplot2")
install.packages("palmerpenguins")
library(tidyverse)
library(ggplot2)
library(palmerpenguins)
ggplot(data=penguins)+
geom_point(mapping=aes(x=flipper_length_mm,y=body_mass_g,color=species))+
labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguin Species",
caption = "Data collected by Dr. Kristen Gorman")+
annotate("text",x=220,y=4000,label="The Gentoos are the largest",color="blue",fontface="bold",size=4.5,angle=30)
Same error displayed after knit-ing
I am trying to use the command
SET !DATASOURCE
to import the whole text from ".txt" file into some textbox
but I cannot find the exact command that would let me import/copy
the whole textfile into the box text, so far I have found {{!COL1}} in SET !DATASOURCE instruction page but It only imports the first line from the .txt file
and not full text
is there any way that I could import/copy whole text file?
and not only some certain lines!
code example:
SET !DATASOURCE TOPIC.txt
SET !DATASOURCE C:\TOPIC.txt
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 0.00
URL GOTO=https://www.********.com
FRAME F=1
EVENTS TYPE=KEYPRESS SELECTOR="HTML>BODY" CHARS="{{!COL1}}"
FRAME F=0
Using Imacros software - Windows 64
Hum, "using iMacros (correct Spelling btw) Software" is a bit vague, if you don't mention the Version...! (And "Windows 64" also...)
=> FCI = iMB v2021.0 'Trial' + Win10_x64. (From your parallel Thread...)
But OK, same Answer/Solution like in your parallel Thread on the iMacros Forum:
Re: import full .txt with SET !DATASOURCE not only certain line
Yep..., '.TXT' Extension is perfect, (doesn't work with '.CSV' Extension), open your File in a TAB_2, (with URL GOTO + file Protocol), and extract it (=> EXTRACT=TXT) on TYPE=PRE, that will extract the whole Content of the File...
(BODY or HTML for the TYPE Param work also, but PRE is the "cleanest"...)
Drag your File from 'Windows Explorer' once to some open Tab in iMB (or any Browser), or open it through 'File > Open File' to get the full URL to reuse for URL GOTO...
That works with iMacros for FF v8.x (v8.8.2 + v8.9.7), I would think it (probably?) also works for iMB v2021.x, if it supports the file Protocol, which I would expect is the case... (I cannot try/test, I installed some 'Trial' Version a few months ago, is already long finished... )
... And just to be "clear", URL GOTO + EXTRACT do "the Job", you don't need !DATASOURCE + !COLn...
I would like to know is there any ruby gem or script to convert multipage pdf file into individual pdf files per pages in ruby. I tried with gems pdf-reader and prawn but not able to solve the problem. Help will be heartly appreciated. Thankyou.
The command-line utility PDFtk can do this easily
pdftk source.pdf cat 1-10 output first10.pdf
pdftk source.pdf cat 10-end output rest.pdf
or
pdftk source.pdf burst
# By default, the output files are named pg_0001.pdf, pg_0002.pdf, etc.
Build a utility method something like this:
def split_pdf(source_file, dest_dir)
Dir.mkdir(dest_dir.to_s)
exec("pdftk #{source_file} burst output #{dest_dir}/p%02d.pdf")
Dir.entries(dest_dir.to_s)
.select { |e| e.ends_with?('.pdf') }
.map { |f| "#{dest_dir}/#{f} }
end
and call it something like this:
source_file = Rails.root.join('public', 'source.pdf')
dest_dir = Rails.root.join('public', 'docs', doc_id)
page_files = split_pdf(source_file, dest_dir)
I picked up O'Reiley's Data Wrangling with Python by Jacqueline Kazil and Katherine Karmul. In ch.5, pg.94, I'm running the following code.
import slate
pdf = 'EN-FINAL Table 9.pdf'
with open(pdf) as f:
doc = slate.PDF(f)
for page in doc[:2]:
print page
I'm using Windows 10, Python 2.7.12 , running slate 0.5.2, pdfminer 20140328 and successfully installed pip. I got the following result:
File "C:\Python27\lib\site-packages\pdfminer\psparser.py", line 215, in fillbuf
raise PSEOF('Unexpected EOF')
pdfminer.psparser.PSEOF: Unexpected EOF
I only know that EOF means 'end of file' and no more data can be read from data source. Does anybody have an idea as to what happened?
If anybody would like to see what file I'm trying to parse, it's right here:
https://github.com/jackiekazil/data-wrangling/tree/master/data/chp5
This solved it for me: https://stackoverflow.com/a/18262661/6843645
Your code would be:
import slate
pdf = 'EN-FINAL Table 9.pdf'
with open(pdf, 'rb') as f:
doc = slate.PDF(f)
for page in doc[:2]:
print page
I want my function to place a piece of markdown in a readme.rmd file. However I would like to include some rcode that that will be executed when a new version of the readme file is rendered.
This is what I want in the readme.rmd:
[![Last-changedate](https://img.shields.io/badge/last%20change-r gsub("-", "--", Sys.Date())-yellowgreen.svg)](/commits/master)"
Which at knitr time will turn into a nicely formated shield with the date.
However to paste this in the document I have to escape some of the characters:
paste0("`r ", "gsub(\"-\", \"--\", Sys.Date())", "`")
But this results into
[![Last-changedate](https://img.shields.io/badge/last%20change-`r gsub(\"-\", \"--\", Sys.Date())`-yellowgreen.svg)](/commits/master)"
And this cannot be rendered by rmarkdown error: unexpected input: gsub(\ ^....
With the suggestion of Chinsoon12:
" would using single quote works? i.e. use paste0("r ", "gsub('-', '--', Sys.Date())", "") "
My problem is solved!
I now paste with double and single quotes.
paste0("https://img.shields.io/badge/last%20change-",
"`r ", "gsub('-', '--', Sys.Date())", "`",
"-yellowgreen.svg")