How to use RStudio to write a RMarkdown file with Stata commands? - rstudio

My problem is explained in the title. I've tried compiling a sample .Rmd I found here: http://www.ssc.wisc.edu/~hemken/Stataworkshops/Stata%20and%20R%20Markdown/
in addition to looking up various resources online to no avail. While my resource, Doug, was able to compile an RMarkdown, I am getting an error for the MWE below.
The MWE is:
---
title: "Stata and R Markdown (Windows)"
author: "Doug Hemken"
date: "July 2015"
output:
html_document:
toc: yes
---
```{r, echo=FALSE, message=FALSE}
require(knitr)
statapath <- "/Applications/Stata/Stata.app"
opts_chunk$set(engine="stata", engine.path=statapath, comment="")
```
### Descriptive Statistics
A simple example.
```{r}
sysuse auto
summarize
```
The output/error from the RStudio console is:
processing file: stata.Rmd
|................ | 25%
ordinary text without R code
|................................ | 50%
label: unnamed-chunk-1 (with options)
List of 2
$ echo : logi FALSE
$ message: logi FALSE
Loading required package: knitr
|................................................. | 75%
ordinary text without R code
|.................................................................| 100%
label: unnamed-chunk-2
running: /Applications/Stata/Stata.app -q -b stata47b9d14e1c.do
Quitting from lines 20-22 (stata.Rmd)
Error in engine(options) :
sh: /Applications/Stata/Stata.app: is a directory
Calls: <Anonymous> ... process_group.block -> call_block -> block_exec -> in_dir -> engine
In addition: Warning message:
running command ''/Applications/Stata/Stata.app' -q -b stata47b9d14e1c.do 2>&1' had status 126
Execution halted

The page you link to points to this page. There, it is written: "For example, if Stata is installed in /Applications/Stata/, then the path to the Stata executable is /Applications/Stata/Stata.app/Contents/MacOS/", and they give appropriate links for all different flavours of Stata. Also, you need to refer to the executable, not the folder where it is located. If I change your MWE as below, everything works for me (note that I use Stata-SE; you might need to change this for your system).
---
title: "Stata and R Markdown (Windows)"
author: "Doug Hemken"
date: "July 2015"
output:
html_document:
toc: yes
---
```{r, echo=FALSE, message=FALSE}
require(knitr)
statapath <- "/Applications/Stata/StataSE.app/Contents/MacOS/stata-se"
opts_chunk$set(engine="stata", engine.path=statapath, comment="")
```
### Descriptive Statistics
A simple example.
```{r}
sysuse auto
summarize
```

Related

Latex not opening png and windows not being able to generate bb

I'm using TexMaker (on Windows 10), using the pdflatex (F6) and yet I can't open the PNG file in the folder of my .tex
\usepackage{graphicx}
\begin{document}
\begin{figure}[h!]
\includegraphics[width=\linewidth]{File.png}
\end{figure}
\end{document}
so I tried to create an bb file from the PNG. I opened cmd at the folder and typed:
ebb File.png
ebb: file not writable for security reasons: File.bb
ebb: fatal: Unable to open output file File.bb
When clicking in the properties and security of File.png I see that my user both: is the owner of the folder and has all permissions set in (even tho I cannot uncheck any of the permissions I have, weirdly).
The folder which I'm working on has that black square marked on the "read only" attribute (in properties). Which I can't quite keep unchecked even tho I'm the owner of it. What is wrong?
EDIT: Here's what happens when I click on show permissions (>properties >security >advanced >show permissions) my user is the owner.
I can't click on anything even tho I'm the owner.
Edit, the logfile:
LOG FILE :
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 20.10) (preloaded format=pdflatex 2020.10.24) 25 OCT 2020 10:47
entering extended mode
**./test.tex
(test.tex
LaTeX2e <2020-10-01> patch level 1
L3 programming layer <2020-10-05> xparse <2020-03-03>
("C:\Program Files\MiKTeX\tex/latex/base\article.cls"
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
("C:\Program Files\MiKTeX\tex/latex/base\size12.clo"
File: size12.clo 2020/04/10 v1.4m Standard LaTeX file (size option)
)
\c#part=\count175
\c#section=\count176
\c#subsection=\count177
\c#subsubsection=\count178
\c#paragraph=\count179
\c#subparagraph=\count180
\c#figure=\count181
\c#table=\count182
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen138
)
("C:\Program Files\MiKTeX\tex/latex/graphics\graphicx.sty"
Package: graphicx 2020/09/09 v1.2b Enhanced LaTeX Graphics (DPC,SPQR)
("C:\Program Files\MiKTeX\tex/latex/graphics\keyval.sty"
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV#toks#=\toks15
)
("C:\Program Files\MiKTeX\tex/latex/graphics\graphics.sty"
Package: graphics 2020/08/30 v1.4c Standard LaTeX Graphics (DPC,SPQR)
("C:\Program Files\MiKTeX\tex/latex/graphics\trig.sty"
Package: trig 2016/01/03 v1.10 sin cos tan (DPC)
)
("C:\Program Files\MiKTeX\tex/latex/graphics-cfg\graphics.cfg"
File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
)
Package graphics Info: Driver file: pdftex.def on input line 105.
("C:\Program Files\MiKTeX\tex/latex/graphics-def\pdftex.def"
File: pdftex.def 2020/10/05 v1.2a Graphics/color driver for pdftex
))
\Gin#req#height=\dimen139
\Gin#req#width=\dimen140
)
("C:\Program Files\MiKTeX\tex/latex/l3backend\l3backend-pdftex.def"
File: l3backend-pdftex.def 2020-09-24 L3 backend support: PDF output (pdfTeX)
\l__kernel_color_stack_int=\count183
\l__pdf_internal_box=\box47
) (test.aux)
\openout1 = `test.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
("C:\Program Files\MiKTeX\tex/context/base/mkii\supp-pdf.mkii"
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count184
\scratchdimen=\dimen141
\scratchbox=\box48
\nofMPsegments=\count185
\nofMParguments=\count186
\everyMPshowfont=\toks16
\MPscratchCnt=\count187
\MPscratchDim=\dimen142
\MPnumerator=\count188
\makeMPintoPDFobject=\count189
\everyMPtoPDFconversion=\toks17
) ("C:\Program Files\MiKTeX\tex/latex/epstopdf-pkg\epstopdf-base.sty"
Package: epstopdf-base 2020-01-24 v2.11 Base part for package epstopdf
Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4
85.
)
<semirreta.png, id=1, 368.1253pt x 99.37125pt>
[1{C:/Users/JoaoV/AppData/Local/MiKTeX/pdftex/config/pdftex.map}] (test.aux) )
Here is how much of TeX's memory you used:
1167 strings out of 480236
17436 string characters out of 2890433
280939 words of memory out of 3000000
17769 multiletter control sequences out of 15000+200000
535555 words of font info for 31 fonts, out of 3000000 for 9000
1141 hyphenation exceptions out of 8191
60i,4n,66p,199b,236s stack positions out of 5000i,500n,10000p,200000b,50000s
<C:/Program Files/MiKTeX/fonts/type1/public/amsfonts/cm/cmr12.pfb><C:/Program F
iles/MiKTeX/fonts/type1/public/amsfonts/cm/cmtt12.pfb>
Output written on test.pdf (1 page, 13448 bytes).
PDF statistics:
15 PDF objects out of 1000 (max. 8388607)
0 named destinations out of 1000 (max. 500000)
6 words of extra memory for PDF output out of 10000 (max. 10000000)
I made a little test:
the real image is suposed to be these two lines: https://ibb.co/yYQCfnd
Remove the draft option, this prevents images from showing up

R markdown Stargazer: knit to pdf issue: Executed haulted

While trying to knit .rmd file to pdf, if code chunks has stargazer function, the file is not knitting to pdf format. I have several tables (both long and short) with combination of regression output via stargazer in latex format but none of them are converting to pdf. I am using MikTeX as LaTeX distribution. I have used following code (as an example)
stargazer(pre.ols.sp01SIOI,pre.ols.sp02SIOI,pre.ols.sp03SIOI,pre.ols.sp04SIOI,
post.ols.sp01SIOI,post.ols.sp02SIOI,post.ols.sp03SIOI,post.ols.sp04SIOI,
style = "qje", type = "latex", header=FALSE, title = "Regression Analysis").
I am getting the following error.
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 2.9.7440 64-bit) entering extended mode
I was unable to find any missing LaTeX packages from the error log Paper1.v7_11Jun2020.log.
Error: LaTeX failed to compile Paper1.v7_11Jun2020.tex. See
https://yihui.org/tinytex/r/#debugging for debugging tips.
In addition: Warning messages:
1: In readLines(log) : line 888 appears to contain an embedded nul
2: In readLines(log) :
incomplete final line found on 'Paper1.v7_11Jun2020.log'
3: In readLines(log) : line 888 appears to contain an embedded nul
4: In readLines(log) :
incomplete final line found on 'Paper1.v7_11Jun2020.log'
5: In readLines(log) : line 888 appears to contain an embedded nul
6: In readLines(log) :
incomplete final line found on 'Paper1.v7_11Jun2020.log'
Execution halted
I have followed the debugging tips mentioned on the yihui.org. But still no luck.
I have also tried to assign the stargazer output and then use kable() and still
it's not working. Moreover, I have tried to using landscape style.
I appreciate any assistance with the issue.
Thanks
Edit: The YAML header
title: XXX
documentclass: article
date: "r format(Sys.Date(),'%d %B, %Y')"
output:
pdf_document:
df_print: paged
fig_caption: yes
highlight: tango
number_sections: yes
citation_package: natbib
keep_tex: yes
bibliography: library.bib
header-includes:
-\usepackage{amsmath}
-\usepackage[utf8]{inputenc}
-\usepackage{autobreak}
-\usepackage{setspace}
-\usepackage{hyperref}
-\usepackage[authoryear]{natbib}
-\usepackage{caption}
-\usepackage{babel
-\usepackage{multirow}
-\usepackage{pdflscape}
-\usepackage{dcolumn}
-\usepackage{rotating}

Rmarkdown does not recognize pandoc filter

I would like to call a pandoc filter (this one) from rmarkdown/RStudio. However, pandoc seems not to recognize the filter. I've handed over the filter in the YAML header. Consider this rmd file:
---
title: "test"
output: pdf_document
header-includes:
- \usepackage{xspace}
pandoc_args:
- --filter
- pandoc-filter/typography.py
---
test
s.S.
The knitting output shows no sign that the filter was handed over to pandoc:
/usr/local/bin/pandoc +RTS -K512m -RTS test_typography-py.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test_typography-py.pdf --template /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in'
The rendered pdf file does not show the effects of the filter, see image
(The effect of the filter is to render a thin space between phrases such as "z.B." or "e.g.".)
What can I do to get this filter run by pandoc via rmarkdown (preferably using the YAML header)?
I just realized (thanks to #NMarkgraf) that I had an intendation error. The correct intendation in YAML is this:
---
title: "test"
header-includes:
- \usepackage{xspace}
output:
pdf_document:
pandoc_args:
- --filter
- typography.py
---
Then it works - the filter is recognized.

SaltStack: Reverse engineering where a file comes from

If you look at a host which was set up be SaltStack, then it is sometimes like looking at a binary file with vi.
You have no clue how the config/file was created.
This makes trouble shooting errors hard. Reverse engineering where a file comes from takes too much time.
My goal: Make it easy to find the way from looking at the unix config file on the minion (created by salt) to the source where this configuration came from. Like $Id$ in svn and cvs.
One idea a friend and I had:
The state file.managed should (optionally) add the source of the file.
Example:
My sls file contains this:
file_foo_bar:
file.managed:
- source:
- salt://foo/bar
Then the created file should contain this comment.
# Source: salt://foo/bar
Of course this is not simple, since there are different ways to put comments into configuration files.
Is this feasible? Or is there a better solution to my goal.
Update
Usually I know what I did wrong and can find the root easily. The problem arises if several people work on a state tree.
This is a starting point where you can get the date and time of the modified file when its managed by Salt by using Salt Pillar.
Lets call our variable salt_managed. Create a pillar file like the following:
{% set managed_text = 'Salt managed: File modified on ' + salt.cmd.run('date "+%Y-%m-%d %H:%M:%S"') %}
salt_managed: {{ managed_text | yaml_dquote }}
Then on the minion when you call the pillar you will get the following result:
$ salt-call pillar.get salt_managed
local:
Salt managed: File modified on 2016-10-18 11:12:40
And you can use this by adding it on the top of your config files for example like this:
{{ pillar.get('salt_managed') }}
Update:
I found a work around that might be useful for someone. Lets say we have a multiple states that could modify the same file. How can we know that State X is the responsible for modifying that file ? by doing the following steps:
1- I have created a state like this one:
Create a File:
file.managed:
- name: /path/to/foofile
- source: salt://statedir/barfile
Add file header:
file.prepend:
- name: /path/to/foofile
- text: "This file was managed by using this salt state {{ sls }}"
The contents of barfile is:
This is a new file
2- Call the state from the minion and this will be the result:
$ salt-call state.sls statedir.test
local:
----------
ID: Create a File
Function: file.managed
Name: /path/to/foofile
Result: True
Comment: File /path/to/foofile updated
Started: 07:50:45.254994
Duration: 1034.585 ms
Changes:
----------
diff:
New file
mode:
0644
----------
ID: Add file header
Function: file.prepend
Name: /path/to/foofile
Result: True
Comment: Prepended 1 lines
Started: 07:50:46.289766
Duration: 3.69 ms
Changes:
----------
diff:
---
+++
## -1,1 +1,2 ##
+This file was managed by using this salt state statedir.test
This is a new file
Summary for local
------------
Succeeded: 2 (changed=2)
Failed: 0
------------
Total states run: 2
Currently the content of foofile is:
This file was managed by using this salt state statedir.test
This is a new file

read pdf document properties from terminal as seen in nautilus

From the terminal I would like to be access the data that is readable when right clicking on a pdf file and selecting "document".
Example :
I have tried reading metadata with tools such as mminfo and pdftk but some files are password protected so they can't show me the meta data.
Help appreciated.
pdfinfo reveals following information for me:
pdfinfo XY.pdf
Title: XY Zufriedenheitsbefragung XY: 2012/5
Producer: Apache FOP Version SVN branches/fop-0_95
CreationDate: Fri May 18 13:38:45 2012
Tagged: no
Pages: 8
Encrypted: no
Page size: 595 x 842 pts (A4)
File size: 33666 bytes
Optimized: no
PDF version: 1.4
but I don't know how it works on encrypted PDFs. But if nautilus can read them - why shouldn't a command line tool?
When I look for pdfinfo, I get 2 alternative answers:
apt-cache search pdfinfo
poppler-utils - PDF-Werkzeuge (basierend auf libpoppler)
xpdf-utils - Portable Document Format (PDF) suite -- utilities

Resources