rmarkdown when I print table in a loop adds "Loading [MathJax]/extensions/MathZoom.js" to my pdf - r-markdown

I am trying to make a pdf with tables using a loop in rmarkdown.
But I get this "Loading [MathJax]/extensions/MathZoom.js" added to the bottom of the pdf.
How do I get rid of this message?
Here is my rmd code
title: "Some tables"
output: html_document
for(i in 1:2){
mytable = kbl(head(mtcars))
cat( print(mytable))
}
I make the pdf by typing the following in the console (typically I run this from another R program).
library(kableExtra)
rmarkdown::render("tables_in_loop.rmd")
pagedown::chrome_print("tables_in_loop.html")
How do I get rid of the loading message?
When I just use
kbl(head(mtcars))
I don't get the message but I want to print out lots of tables with a loop.
I know Rmd can do pdfs, but I get an error about running pdflatex.exe from
C:\AppData\Roaming\TinyTeX\bin\win32
I don't have administrative rights to execute this. If you have suggestions about this they are much appreciated.
Also I have a 64 bit windows 10 computer and I'm running R in 64.
Thank you so much,
Jennifer

I figured it out, I need to just use cat(mytable) not cat(print(mytable))

Related

tbl_summary Error message in UseMethod("ungroup")

I have a tbl_summary which outputs great when run in a script, however I am writing a report in rmarkdown and every time I knit to pdf I get an error message:
Error in UseMethod("ungroup")
(see image below)
Why is this happening? All the variables are continuous except for 'Region' which is what I'm grouping by. Again it outputs fine until I go to knit the file.

Problem with filepath and rendering a stargazer table

a newbe here.
I'm writing an essay in Rmarkdown and I want to render a PDF. When I try to import an excel sheet with the commands:
dat1 <- read.xlsx("Seminararbeit.xlsx", 2L)
and then create a table with stargazer, I keep on getting this Error:
Error in basename(filePath) :
unable to translate 'my-file-path-goes-here' to native encoding
It looks like the table is actually created with stargazer, but it doesn't show up when I knit the file. I tried to Reinstall R and Rstudio (I believe I have the newest version of both) but nothing worked. Is the file path too long? I have a MacOS, is that the problem?
Please help, it's driving me nuts!

RMarkdown - Change Inline Code Color *without changing workflow*

I teach an introductory statistics course using R Markdown in RStudio (Server). We have students knit to html_notebooks, and we often have them use inline code to report various elements of their statistical analyses. It'd be really helpful for grading purposes if we could have the result of inline code output in a different color -- that way we could easily see if they were indeed using inline code or if they copy-pasted a number from their output into raw text.
There's a couple of ideas for solutions posted here, but these won't super work in my case. These are introductory students who are generally kinda afraid of RStudio to begin with, so asking them to do anything complicated with text_spec or sprintf will likely cause mild riots. I really need something that won't change students' workflow at all.
I wonder if there's any way to configure things either on the backend in RStudio Server (maybe by messing with knitr?), or through some kind of <style> tag wizardry in the preamble, so that inline code will print its results in a different color.
Thanks!
EDIT: Arthur Berg below has provided something that's almost exactly what I need. Here's a MWE:
---
title: "test knit_hook"
output: html_document
---
```{r, setup, include="FALSE"}
knitr::knit_hooks$set(inline=function(x){paste0("<span style=\"color: #0000FF;\">",
x,"</span>")})
```
`r pi`
The only issue with this is that it doesn't work if I change to html_notebook in the YAML header and thus use the "Preview" button in the RStudio IDE. For external reasons, it's important for us to have the output type as html_notebook. Anyone know how we might modify this to get it to work with html_notebook?
A way to achieve this without changing the workflow too much is to create your own format (e.g. html_notebook2) that is derived from the original but modifies the inline hook of knitr.
To get started you can check out this document.
Basic steps include
Create a new R package
Within this project run usethis::use_rmarkdown_template(). This creates the folder structure for your new format.
Edit skeleton.rmd and template.yaml
Define your format in a R file which has the same name html_notebook2.R(kind of a convention).
The content of the html_notebook2.R file could be
#'#import knitr
set_hooks <- function() {
default_hooks <- knit_hooks$get()
list(
inline = function(x) {
paste0("<span style=\"color: #FF0000;\">", x,"</span>")
})
}
#' #importFrom rmarkdown output_format knitr_options pandoc_options html_notebook
#' #export
html_notebook2 = function() {
output_format(
knitr = knitr_options(knit_hooks = set_hooks()),
pandoc = pandoc_options(to = "html"),
clean_supporting = FALSE,
base_format = html_notebook()
)
}
In the first part we define a new inline hook which only changes the font color.
The second part is the definition of the new format.
After building and installing the package you can create a new rmarkdown document and use output: packagename::html_notebook2 as the output format. All inline code output will be colored red using my code. Here is an example:
---
title: "Inline"
output: cformat::html_notebook2
---
## R Markdown
`r pi`
I created such a package and you can find it on GitHub. Feel free to copy it and rename it (cformat is a pretty lame working title ;) ).
Notice though that your students could change the color manually using HTML/CSS anyways. A way around could be some kind of key generation using a certain rule (unknown to the students obviously). For each inline chunk a key is generated and embedded using
paste0("<span code=", key," style=\"color: #FF0000;\">", x,"</span>")
If a valid key is embedded, the output was generated using R and not simply copied.
For those looking for a fix to a simple R markdown document, adding this line changes the inline output to blue.
knitr::knit_hooks$set(inline=function(x){paste0("<span style=\"color: #0000FF;\">", x,"</span>")})

How to make a web page to totally display when loaded in python selenium?

The main objective I have is to read a table in a webpage and account for the total element it has. But since you have to scroll down to find another elements not 'chased' by this sentece
table_css=driver.find_elements_by_id('DeletButtn')
then I decided to zoom in down to 30% to catch them all. But no way I've used is working when trying to zoom in:
driver.execute_script("document.body.style_zoom='30%'")
driver.execute_script("document.body.style.zoom='30%'")
driver.execute_script("document.body.style.zoom='0.3'")
do not work
I have also tried to use key and send keys, but they have been worthless too:
html = driver.find_element_by_tag_name("body")
html.send_keys(Keys.CONTROL, Keys.SUBTRACT)
driver.Keys(html, "ctrl").Keys(html, "-").perform()
action = ActionChains(driver)
action.key_down(Keys.CONTROL).key_down(Keys.SUBTRACT).perform()
None of these combinations have worked up til now. They haven't show me any error so far, so I do not know what I am doing wrong.
I am using python 2.7, geckodriver and Firefox
Thanks for your help and greetings!

How do I output calabash query results to a textFile

ok, I've read all the calabsh query docs on xamarin for android and iOS and the Ruby file class and still can't find the answer, so if anyone can help then that would be great.
What I trying to do is run querys in the calabash-android console window and write those results to a file on the fly.
so for instance : query("this is my query", :type (class etc..)
I can also do query("*") - I will then take the text output and collate the information I require to build up an elements 'dictionary'
Ive tried query("*") f.write("C:\myFileName.txt",'w') and the console complains.. I've also tried multiple operators on the query (f.write, f.open).
thanks guys in advance.
The calabash console is just ruby's irb console with the calabash modules loaded. As such you can use any ruby commands to get things done. This answer should cover you - How to write to file in Ruby?
e.g.
open('out.txt', 'a') { |f| f.puts query('*')}
will append the query results to out.txt.
or
outputs = []
outputs << query('*')
outputs << query("* text:'OK'")
open('out.txt', 'a') { |f| f.puts output}