Giter Club home page Giter Club logo

statamarkdown's People

Contributors

hemken avatar remlapmot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

statamarkdown's Issues

Statamarkdown fails to include output when run from a folder containing a space - MacOS

When running a Statamarkdown file stored in a MacOS path that contains a space, no Stata output is included. All Markdown and Stata code is included and formatted correctly, but no Stata output is included.

The problem is solved by running the file from a path with no spaces. Also, the issue does not appear when running in Windows.

I think that this issue may relate to the issue described in #13. My OneDrive for Business path includes a (non-removable) space, so Statamarkdown files cannot be run from my OneDrive.

A clue: the working directory contains a small log file called OneDrive.log consisting only of the lines:

Running /Users/td/OneDrive - UNSW/Software/RMarkdown/Statamarkdown/profile.do ...

file /Users/td/OneDrive.do not found
r(601);

It looks like this could be fixed by quoting the path so that the spaces could be incorporated, but I couldn't work how this could be done in the Statamarkdown code.

Can't get collectcode to work at all in R Markdown

I'm trying to run the linking code blocks in rmd vignette and I cannot get collectcode to work at all. I can successfully run a single chunk, but get empty results when I try to run the second stata chunk in the vignette. Any help is appreciated.

unable to install package

I am unable to install the package at the moment. I get the following error: Malformed Depends or Suggests or Imports or Enhances field.
Offending entries:
Suggests: rmarkdown
Entries must be names of packages optionally followed by '<=' or '>=',
white space, and a valid version number in parentheses.

See section 'The DESCRIPTION file' in the 'Writing R Extensions'
manual.

Statamarkdown shows no output

I really love Statamarkdown, but unfortunately on my new computer it does not show any output when I compile the R markdown document.

This is the output that R.version gives me:

platform x86_64-apple-darwin17.0
arch x86_64
os darwin17.0
system x86_64, darwin17.0
status
major 4
minor 0.3
year 2020
month 10
day 10
svn rev 79318
language R
version.string R version 4.0.3 (2020-10-10)
nickname Bunny-Wunnies Freak Out

And this is an example code that is not working:

library(Statamarkdown)
statapath <- find_stata()
knitr::opts_chunk$set(engine.path=list(stata=statapath), comment=NA)
sysuse auto
summarize

Any help you could give would be greatly appreciated.

Thanks,
Christian

Stata engine is located, but no output shown

I have already installed Statamarkdown on R, and have already located my Stata engine. Then, i followed the examples, but i even cannot get the output of sysuse auto. I can knit the html as well as word document. But there is no output apart from my codes there. I am a MacOS (version 11.2.3) user. Please kindly help me

undesired output when `collectcode=TRUE`

As documented, collectcode=TRUE is a chunk option that helps collecting Stata code across chunks.

While this works neatly, the outputs of the second (and any further) chunks follwing the first with collectcode=TRUE contain an undesired echo at the top:

Running .......\profile.do

For instance, when running a second chunk with {stata stata2, echo = T,collectcode=TRUE}

   reg mpg price i.foreign ,  noheader  

yields this output:

reg mpg price i.foreign ,  noheader  
Running C:\Cloud\Methods\prog\profile.do . reg mpg price i.foreign ,  noheader  
------------------------------------------------------------------------------
         mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       price |   -.000959   .0001815    -5.28   0.000     -.001321    -.000597
             |
     foreign |
    Foreign  |   5.245271   1.163592     4.51   0.000     2.925135    7.565407
       _cons |   25.65058   1.271581    20.17   0.000     23.11512    28.18605
------------------------------------------------------------------------------

Here's my RMarkdown repex:

---
title: "Statamarkdown output problem"
output: html_document
---

```{r setup, include = F}
library(Statamarkdown)
```


First chunk is clean:

```{stata stata1,collectcode=TRUE}
sysuse auto
su mpg price
```

Second Stata Output contains undesired `Running .......\profile.do` output:

```{stata stata2, echo = T,collectcode=TRUE}
reg mpg price i.foreign ,  noheader  
```

Problem persists even in chunks with `collectcode=FALSE`:

```{stata new_data, echo = T,collectcode=F}
webuse bpwide, clear
su sex agegrp
```

`cleanlog = F` does not do the trick:
```{stata new_data2, echo = T,collectcode=F, cleanlog = FALSE}
webuse bpwide, clear
su sex agegrp
```

Avoiding collectcode=T alltogether, i.e. load and preparing the data for each chunks would of course be a workaround, but extremely tedious.

I also posted a SO question here, in case it's more a misunderstanding on my part rather than a bug.
Any idea/help is very much appreciated!
Thank you very much for this very useful package!

In v1.3 of the markdown package `markdownToHTML()` is now additionally `mark_html()`

Hi Doug

I notice that in the recently released version 1.3 of the markdown package they have renamed markdownToHTML() to mark_html(). Thankfully, they are still exporting the old function name.

The helpfile

?markdown::markdownToHTML

now shows
Screenshot 2022-11-09 at 05 23 39

So the helpfile examples in find_stata() and stata_engine() still run, but hopefully worth knowing anyway.

Output from `regress` command cuts out lines from coefficient table

Take the following example (unfortunately I can't share the data so it's not a reprex):

regress positiveaffect age_group i.male_s0 i.study_agrup i.healtheat i.moderhigh_phy_activ_s0 i.no_daily_smoker_s0 i.no_heavy_alcohol_s0 i.sleep_quality

Here is the output from Stata:

      Source |       SS           df       MS      Number of obs   =     4,582
-------------+----------------------------------   F(10, 4571)     =     20.85
       Model |  245.101294        10  24.5101294   Prob > F        =    0.0000
    Residual |  5374.37876     4,571  1.17575558   R-squared       =    0.0436
-------------+----------------------------------   Adj R-squared   =    0.0415
       Total |  5619.48005     4,581  1.22669287   Root MSE        =    1.0843

------------------------------------------------------------------------------------------
          positiveaffect |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------------------+----------------------------------------------------------------
               age_group |   .1035648   .0245478     4.22   0.000     .0554393    .1516903
               1.male_s0 |   .1587417   .0330365     4.81   0.000     .0939743    .2235091
                         |
             study_agrup |
                  first  |  -.0424049   .0443068    -0.96   0.339    -.1292676    .0444578
         secundary/bach  |  -.0557807   .0462165    -1.21   0.228    -.1463874     .034826
             university  |   .0165693   .0569458     0.29   0.771    -.0950719    .1282106
                         |
             1.healtheat |   .1187273   .0357351     3.32   0.001     .0486692    .1887854
1.moderhigh_phy_activ_s0 |   .1419471   .0354298     4.01   0.000     .0724877    .2114066
    1.no_daily_smoker_s0 |   .1421319   .0404974     3.51   0.000     .0627375    .2215264
   1.no_heavy_alcohol_s0 |  -.1845019   .0934702    -1.97   0.048    -.3677487   -.0012552
         1.sleep_quality |   .3791113   .0391579     9.68   0.000     .3023428    .4558798
                   _cons |   4.249539   .1167263    36.41   0.000     4.020699    4.478379
------------------------------------------------------------------------------------------

While the output given by the Rmarkdown document is

      Source |       SS           df       MS      Number of obs   =     4,582
-------------+----------------------------------   F(10, 4571)     =     20.85
       Model |  245.101294        10  24.5101294   Prob > F        =    0.0000
    Residual |  5374.37876     4,571  1.17575558   R-squared       =    0.0436
-------------+----------------------------------   Adj R-squared   =    0.0415
       Total |  5619.48005     4,581  1.22669287   Root MSE        =    1.0843

------------------------------------------------------------------------------
positiveaf~t |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
   age_group |   .1035648   .0245478     4.22   0.000     .0554393    .1516903
             |
 study_agrup |
      first  |  -.0424049   .0443068    -0.96   0.339    -.1292676    .0444578
secundary~h  |  -.0557807   .0462165    -1.21   0.228    -.1463874     .034826
 university  |   .0165693   .0569458     0.29   0.771    -.0950719    .1282106
             |
1.moderhig~0 |   .1419471   .0354298     4.01   0.000     .0724877    .2114066
1.no_daily~0 |   .1421319   .0404974     3.51   0.000     .0627375    .2215264
1.no_heavy~0 |  -.1845019   .0934702    -1.97   0.048    -.3677487   -.0012552
1.sleep_qu~y |   .3791113   .0391579     9.68   0.000     .3023428    .4558798
       _cons |   4.249539   .1167263    36.41   0.000     4.020699    4.478379
------------------------------------------------------------------------------

It can be seen that the lines for some of the coefficients in the table are missing, e.g. the coefficient for 1.male_s0.
This doesn't seem to be a problem with the model estimation, as the rest of the coefficients, degrees of freedom, and statistics are coincident in values. Therefore, it seems like some lines are being stripped off the output.

Interestingly, using the chunk option comment = '##' gives the correct output.

collectcode=TRUE not working to vinculate two code chunks

Hello, just discover this package to integrate Stata into my R workflows.

I confirm every stata chunk works fine independently, but doesn't remember the previous stata chunk.

Syntax:

Setup


pacman::p_load_gh("hemken/Statamarkdown")
knitr::opts_chunk$set(
  engine.path = list(stata = "C:/Program Files/Stata-MP-16.0/StataMP-64"),
  error=TRUE, 
  cleanlog=TRUE, 
  comment=NA
  )#where is stata

Stata Markdown

sysuse auto
summarize

(1978 Automobile Data)
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
make | 0
price | 74 6165.257 2949.496 3291 15906
mpg | 74 21.2973 5.785503 12 41
rep78 | 69 3.405797 .9899323 1 5
headroom | 74 2.993243 .8459948 1.5 5
-------------+---------------------------------------------------------
trunk | 74 13.75676 4.277404 5 23
weight | 74 3019.459 777.1936 1760 4840
length | 74 187.9324 22.26634 142 233
turn | 74 39.64865 4.399354 31 51
displacement | 74 197.2973 91.83722 79 425
-------------+---------------------------------------------------------
gear_ratio | 74 3.014865 .4562871 2.19 3.89
foreign | 74 .2972973 .4601885 0 1

Frequency Tables


tab1 foreign 

no variables defined
r(111);

end of do-file
r(111);


When i see the root directory of my project, i identify when i run the first stata chunk some files are created and then deleted. Why is this happening? i tried executing my Stata as administrator and doesn't work either. I have Stata 16.

Let me know if there is solution to my problem.

Thanks,
Santiago

Ps. please read it in raw code because the formatting is not helping.

Ubuntu 18.04 installation issue

library(devtools) # before this you may need to install devtools
install_github("hemken/Statamarkdown")

Downloading GitHub repo hemken/Statamarkdown@master
✔ checking for file ‘/tmp/RtmpDK3s0n/remotes292552702801/Hemken-Statamarkdown-4581096/DESCRIPTION’ ...
─ preparing ‘Statamarkdown’:
✔ checking DESCRIPTION meta-information
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘Statamarkdown_0.3.8.tar.gz’

Installing package into ‘/home/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)

  • installing source package ‘Statamarkdown’ ...
    ** R
    ** inst
    ** preparing package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** installing vignettes
    ** testing if installed package can be loaded
    Warning: l'exécution de la commande ''which' stata' renvoie un statut 1
    Stata found at
    Warning: l'exécution de la commande ''which' stata' renvoie un statut 1
    Error: package or namespace load failed for ‘Statamarkdown’:
    .onAttach failed in attachNamespace() for 'Statamarkdown', details:
    call: if (file.exists(file.path(dirname(find_stata(message = FALSE)),
    error: l'argument est de longueur nulle
    Erreur : le chargement a échoué
    Exécution arrêtée
    ERROR: loading failed
  • removing ‘/home/R/x86_64-pc-linux-gnu-library/3.4/Statamarkdown’
    Error in i.p(...) :
    (converti depuis l'avis) installation of package ‘/tmp/RtmpDK3s0n/file292548567b2c/Statamarkdown_0.3.8.tar.gz’ had non-zero exit status
    De plus : Warning message:
    In is.na(remote_deps$package) :
    is.na() appliqué à un objet de type 'NULL' qui n'est ni une liste, ni un vecteur

using the output from stata in R

Useful package...thanks!
Is it possible to make the results from stata available to R for use in further processing downstream?

Stupid example, but say I have

```{stata}
summ var
```

and want to use r(mean) in other calculations in following R chunks

r(table) after regress and passing it to kable perhaps or some such would probably be a better example, but I'm sure you get the idea.

I guess the current solution would be similar to that proposed for inline results? Would be cool to be able to specify a (vector of?) outputs to pass from stata back to R...

On a slightly different note, maybe you can add a link to your ssc.wisc site the github repo... in the readme and/or in the repo settings. It's very useful, but not mentioned that I saw...

knitr 1.45 seems to have broken the collectcode chunk option

Hi Doug

knitr 1.45 was released on 30th October.

I think I notice that it has broken the collectcode chunk option.

I have put a demo at https://github.com/remlapmot/collectcode-error (the error is still present under Yihui's latest version on GitHub, but I didn't report this in the knitr repo yet).

I haven't traced which change in knitr 1.45 causes the error but I know the differences between the knitr 1.44 and 1.45 can be viewed at

yihui/knitr@v1.44...v1.45

If we can work out which was the breaking change maybe we should report to Yihui?

All the best
Tom

Stata graphics hook

Is it possible to use a chunk option to plot specific lines of stata code following: [https://www.ssc.wisc.edu/~hemken/Stataworkshops/Statamarkdown/including-stata-graphs.html#saving-a-stata-graph](from here)

It would be nice to simplify the process of exporting graphs and including them in the Rmd output. I'd be happy to give it a shot and iterate!

possible typo in commented out code in find_stata() helpfile example

I was wondering if there might be a small typo in the commented out code in the example on the helpfile for find_stata().

On the line here should #engine.path=stataexe, be replaced with #engine.path = list(stata = stataexe) (as per your code in the Basic Use vignette) for the code to run when not commented out?

When I save the example Rmd code as a separate file and delete the 2 engine.path=stataexe chunk options and click the Knit button in RStudio the current code fails with an error message

Error: $ operator is invalid for atomic vectors
Execution halted

but with the edit it runs.

i.e. edited version is

## Not run: 
indoc <- '
# An R console example
## In a first code chunk, set up with
```{r}
library(Statamarkdown)
stataexe <- find_stata()
knitr::opts_chunk$set(engine="stata", engine.path = list(stata = stataexe),
  error=TRUE, cleanlog=TRUE, comment=NA)
```
## Then mark Stata code chunks with
```{r, engine="stata", collectcode=TRUE}
sysuse auto, clear
generate gpm = 1/mpg
summarize price gpm
```

## A later chunk that depends on the first.
```{r, engine="stata"}
regress price gpm
```
'
# To run this example, remove tempdir().
fmd <- file.path(tempdir(), "test.md")
fhtml <- file.path(tempdir(), "test.html")

knitr::knit(text=indoc, output=fmd)
markdown::markdownToHTML(fmd, fhtml)

Happy to make a PR if that's easier.

Not sending commands to stata correctly

Using RStudio Version Version 1.1.463 and Stata16 and the following code:
```{stata, engine.path="C:/Program Files/Stata16/StataIC-64", comment=""}
sysuse auto
summarize
```

I receive this error in stata:
. C:\Users\kb289\AppData\Local\Temp\RtmpCGQRnq\chunk-code-227c3e2b33.txt
command C is unrecognized

Trying this is stata works, but I couldn't figure out how to get markdown to send the command like this:
do "C:\Users\kb289\AppData\Local\Temp\RtmpCGQRnq\chunk-code-227c3e2b33.txt"

Error: node stack overflow

I'm attempting to use a .dta file downloaded from a google drive. I am running both stata code and r on it - thus Statamarkdown. However, I'm encountering an "Error: node stack overflow" attempting to run any stata after the download.

Here's my sessionInfo:

R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.6

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] forcats_0.5.2 stringr_1.4.1 dplyr_1.0.10 purrr_0.3.4 readr_2.1.2 tidyr_1.2.1 tibble_3.1.8
[8] ggplot2_3.3.6 tidyverse_1.3.2 gtsummary_1.6.1 labelled_2.10.0 knitr_1.40 googledrive_2.0.0 rio_0.5.29
[15] conflicted_1.1.0 here_1.0.1 Statamarkdown_0.7.1 pacman_0.5.1

loaded via a namespace (and not attached):
[1] httr_1.4.4 jsonlite_1.8.0 foreach_1.5.2 modelr_0.1.9 assertthat_0.2.1 googlesheets4_1.0.1 cellranger_1.1.0
[8] yaml_2.3.5 pillar_1.8.1 backports_1.4.1 glue_1.6.2 digest_0.6.29 rvest_1.0.3 colorspace_2.0-3
[15] htmltools_0.5.3 pkgconfig_2.0.3 broom_1.0.1 haven_2.5.1 scales_1.2.1 openxlsx_4.2.5 tzdb_0.3.0
[22] generics_0.1.3 ellipsis_0.3.2 cachem_1.0.6 withr_2.5.0 cli_3.4.0 magrittr_2.0.3 crayon_1.5.1
[29] readxl_1.4.1 evaluate_0.16 memoise_2.0.1 fs_1.5.2 fansi_1.0.3 doParallel_1.0.17 broom.helpers_1.8.0
[36] xml2_1.3.3 foreign_0.8-82 tools_4.1.2 data.table_1.14.2 hms_1.1.2 gargle_1.2.1 lifecycle_1.0.2
[43] munsell_0.5.0 reprex_2.0.2 zip_2.2.1 compiler_4.1.2 rlang_1.0.5 grid_4.1.2 gt_0.7.0
[50] iterators_1.0.14 rstudioapi_0.14 rmarkdown_2.16 gtable_0.3.1 codetools_0.2-18 DBI_1.1.3 curl_4.3.2
[57] R6_2.5.1 lubridate_1.8.0 fastmap_1.1.0 utf8_1.2.2 rprojroot_2.0.3 stringi_1.7.8 parallel_4.1.2
[64] Rcpp_1.0.9 vctrs_0.4.1 dbplyr_2.2.1 tidyselect_1.1.2 xfun_0.33

Here's the code that seems to be giving me trouble:

{r}
#| label: r: download data from repo

googledrive::drive_download(
  "https://drive.google.com/file/d/1vsSGvMdsn92-vhYvKM-o2e3Q6nywVCtr/view?usp=sharing", 
  path = "temp_repo/adTurn_survey.dta", 
  overwrite = TRUE
)

googledrive::drive_download(
  "https://drive.google.com/file/d/1LwLAVyogYsDwd_4B8zpQmJ9ONjdgRvO6/view?usp=sharing", 
  path = "temp_repo/adTurn_list.dta", 
  overwrite = TRUE
)
{stata stata: prep data, collectcode=TRUE}
clear all

// load data
use temp_repo/adTurn_survey

// remove duplicate variables 
drop Check1* Q R S T

// merge with Administrator data
merge 1:1 ccmu1 firstname lastname using temp_repo/adTurn_list
save "temp_repo/adTurn_raw_merge", replace

Further: Not running the r download chunk does not result in the stata chunk throwing an 'Error: node stack overflow'. I don't understand enough about node stacks to know what to do here. Is there a way to reset or clear them?

Further further: Ok - running any r chunk prompts the 'Error: node stack overflow' error when subsequently running a stata chunk.

Update to RStudio version 1.4.1106 causes "play" button to disappear

Hi,

I have been successfully using Statamarkdown for a couple of months - and it's been super useful - so thanks!

I updated both R (R version 4.0.4) and RStudio (version 1.4.1106), which unfortunately has caused the "Run current chunk" or "play" button to disappear.

The document knits fine, it is just that I cannot run individual chunks in my Rmd file, nor can I run all chunks above/below if there are Statamarkdown chunks.

I tried to reinstall earlier version of both R (R version 3.6.3 - but Statamarkdown not supported) and RStudio (version 1.3.1093 - but problem remains).

I also tried to solve the issue by following advice from RStudio issue #6220, but I get an error message:

sysuse auto
Error: unexpected symbol in "sysuse auto"

I would greatly appreciate your help in trying to find a solution.

Thanks,

Mo

`oprofile` not found

I try to compile Rmd file with stata chunks with option eval=FALSE.
This results in error with message oprofile not found.
I use StataMP 13

Output of Statamarkdown show a message "running"

Hello,

First of all, I would like to thank you in advance for your consideration of this question.

I tried to run a code in RMarkdown using the Statamarkdown package and now I am using a certain database opened through the use of the popular codes in Stata: (1) defining my "cd", and then (2) using the command "use" and giving the name of my dta file.

As follows
(using the chunks: for the first one: {stata, include = FALSE, collectcode=TRUE}) and for the second one (```{stata, message = FALSE, collectcode=TRUE})

cd "C:\Users\Gabriel\Desktop\replication_labour\replication_markdown\stata_files"
use data_candidates_mainsample.dta, clear

When I run my entire code, it is always appearing a message in form of: "running C:....(that is my defined directory).do..." in the html output (in each of the codes that I am trying to run), as it could be observed in the attached image.

Captura

I think I can solve the first code by adding the option "include=FALSE" to that chunk, but if I use this option in the other codes, the output will be not shown. I tried, as we can see in my code, with the option "message=FALSE" in the chunk, but it was not useful for solving this message.

Could you please give me any piece of advice to try to solve this problem and get the outputs without that message?

Best regards,
Gabriel

Unexpected Output

Hello everyone, dear Mr. Hemken,

I am having issues with the output of the following codechunk:

graph box income, ///
  over(state, sort(income) label(angle(65))) ///
  by(sex)
quietly graph export img/graphbox01.pdf, replace

As you can see below, the second and third code lines are repeated in the classical stata output style, despite having the cleanlong-option set to TRUE.
output_issue

I suspect some issue with spreading the command syntax over several lines using the three slash signs, because this error does not occur when I write the command syntax in just one line.

This Code:

graph box income, over(state, sort(income) label(angle(65))) by(sex)
quietly graph export img/graphbox01.pdf, replace

produces just one line of code in the output and does not repeat it using the stata output style, which is what I also want to achieve while still using the three slashes to distribute the code syntax over several lines.
grafik

Any help with this issue would be greately appreciated!

Kind regards,
Julien

`collectcode=TRUE` only works for Rmarkdown documents in the root folder of the project (when chunks are set to evaluate in the root folder)

Take the following example, adapted from the Statamarkdown handbook:

---
title: "R Notebook"
output:
  html_document:
    df_print: paged
---

```{r, include=FALSE}
library(Statamarkdown)
```


A first code block:

```{stata first-Stata, collectcode=TRUE} 
sysuse auto
generate gpm = 1/mpg
summarize price gpm
```

A second, later code block:

```{stata second-Stata} 
regress price gpm
```
  1. Open Rstudio
  2. Click on "Tools" -> "Global Options..." -> "R Markdown".
  3. In "Evaluate chunks in directory", select "Project" from the dropdown menu, then click "OK"
  4. Create a new Rstudio project
  5. Save the previous example as a .Rmd file in the root folder.
  6. Knit the example; everything goes fine.
  7. Now create a subfolder (e.g. notebooks), and copy the .Rmd file into that subfolder.
  8. Knit the version of the .Rmd file in the subfolder.
  9. The second chunk does not run properly, allegedly because collectcode=TRUE fails.

A profile.do is created in the subfolder and then deleted. However, it might be the case that Stata "looks for" the profile.do in the root directory of the project somehow.

Now:

  1. Click on "Tools" -> "Global Options..." -> "R Markdown".
  2. In "Evaluate chunks in directory", select "Document" from the dropdown menu, then click "OK"

Repeat step 5; the second chunk now runs properly. My guess is that this issue is related to #12 , and most probably to this response. However, I think this is a new use case that may help shed some light into the solution.

eval=FALSE does not work in combination with cleanlog=FALSE

Dear Mr. Hemken,

I have a problem with displaying code. I want to display certain Stata commands without showing the respective result. It is possible to use the chunk options "eval=FALSE" or "results="hide"" to do so, however these chunk options don't seem to be compatible with the chunk option "cleanlog=FALSE", as it does not show anything when used together, not the result and not the command. As I would like to display Stata code in the typical black and white format, this is somewhat bothersome. Is there a way to suppress the output and merely show the Stata commands while still using "cleanlog=FALSE" ? I have attached a pdf to exemplify my problem and would be very thankful for your help!

Kind regards,
Julien

Stata-Block-Test.pdf

output font size change, or width change?

How to change the font size in output? Currently the output always folds because it exceeds the width. See the example:

reg mpg price

  Source |       SS           df       MS      Number of obs 

= 74
-------------+---------------------------------- F(1, 72)
= 20.26
Model | 536.541807 1 536.541807 Prob > F
= 0.0000
Residual | 1906.91765 72 26.4849674 R-squared
= 0.2196
-------------+---------------------------------- Adj R-squared
= 0.2087
Total | 2443.45946 73 33.4720474 Root MSE
= 5.1464



     mpg | Coefficient  Std. err.      t    P>|t|     [95% co

n
f. interval]
-------------+---------------------------------------------------

   price |  -.0009192   .0002042    -4.50   0.000    -.001326

3
-.0005121
_cons | 26.96417 1.393952 19.34 0.000 24.1853
8
29.74297



Loops and Collectcode

Should loops in stata code be strictly contained within a code chunk in the rmd? In other words, will collectcode=True option allow parts of a loop to be split in multiple chunks?

Context: I split parts of the loop in different chunks and it failed.

Installation Failure

I'm trying to install the package and get the following error

library(devtools)
Loading required package: usethis
install_github("hemken/Statamarkdown")
Downloading GitHub repo hemken/Statamarkdown@HEAD
√ checking for file 'C:\Users\E-ITX\AppData\Local\Temp\RtmpcV3zgB\remotese383cd31ce8\Hemken-Statamarkdown-a68a8b9/DESCRIPTION' ...

  • preparing 'Statamarkdown':
    E checking DESCRIPTION meta-information ...
    Malformed Depends or Suggests or Imports or Enhances field.
    Offending entries:
    Suggests: rmarkdown
    Entries must be names of packages optionally followed by '<=' or '>=',
    white space, and a valid version number in parentheses.

    See section 'The DESCRIPTION file' in the 'Writing R Extensions'
    manual.

Any help to resolve this is appreciated..

Stata output formatting issues.

Funny little thing I noted today while using the great {Statamarkdown} package.

It seems like some of the Stata output gets cut off when running in an Rmarkdown document, and in a knitted document dependent on spacing in the code chunk. The the top of the Stata code output in Rmarkdown is always cut off, but in the knitted word output, it looks fine if there is a empty line at the top of the code chunk before the Stata command.

Output cut off in Rmarkdown doc:
image

Output normal in knitted word doc from same Rmd:

image

Cut off exposure status headers in word doc when no space in code chunk:
image

Knit word output here:

github_issue.docx

Rmd text here (sorry cannot attach .Rmd extensions):

rmd_text_for_github_issue.txt


My session information:

R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Statamarkdown_0.7.0

loaded via a namespace (and not attached):
 [1] compiler_4.1.1  fastmap_1.1.0   htmltools_0.5.2 tools_4.1.1     yaml_2.2.1      rmarkdown_2.10 
 [7] knitr_1.33      digest_0.6.27   xfun_0.25       rlang_0.4.11    evaluate_0.14

Feature Request: purl-style function for stata code

I wonder if there is any value in making a knitr::purl-style function that outputs a .do file with just the Stata code in it? I've done this for my own files. Not sure it is sufficiently robust for production, but might be a good start if you're inclined to add something like this to the package. One thing this doesn't do that purl() does is capture the chunk options and return them either as comments or roxygen documentation tags.

purl_do <- function(fname, ...){
  rl <- readLines(fname)
  starts <- grep("^```\\{stata", rl)
  if(length(starts) > 0) {
    ends <- which(rl == "```")
    ends <- sapply(starts, \(x)min(ends[which(ends > x)]))
    starts <- starts+1
    ends <- ends-1
    res <- lapply(seq_along(starts), \(i)rl[starts[i]:ends[i]])
    outfile <- gsub("(.*)\\.[Rr]md$", "\\1.do", fname)
    for(i in seq_along(res)){
      cat(res[[i]], sep="\n", file=outfile, append=TRUE)
      cat("\n\n", file=outfile, append=TRUE)
    }
  }else{
    stop("No Stata code in document.\n")
  }
}

Problems with instalation.

I have problems installing the package, here:

`> devtools::install_github("Hemken/Statamarkdown")
Downloading GitHub repo Hemken/Statamarkdown@master
✔ checking for file ‘/tmp/RtmpEuzkGc/remotes1b707aa350e9/Hemken-Statamarkdown-0457a3a/DESCRIPTION’ ...
─ preparing ‘Statamarkdown’:
✔ checking DESCRIPTION meta-information ...
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘Statamarkdown_0.3.9.tar.gz’

Installing package into ‘/home/mariogs/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)

  • installing source package ‘Statamarkdown’ ...
    ** using staged installation
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** installing vignettes
    ** testing if installed package can be loaded from temporary location
    Warning in system2("which", "stata", stdout = TRUE) :
    running command ''which' stata' had status 1
    Stata found at
    Error: package or namespace load failed for ‘Statamarkdown’:
    .onAttach failed in attachNamespace() for 'Statamarkdown', details:
    call: if (stataexe != "") {
    error: argument is of length zero
    Error: loading failed
    Execution halted
    ERROR: loading failed
  • removing ‘/home/mariogs/R/x86_64-pc-linux-gnu-library/3.6/Statamarkdown’
    Error in i.p(...) :
    (converted from warning) installation of package ‘/tmp/RtmpEuzkGc/file1b701622620d/Statamarkdown_0.3.9.tar.gz’ had non-zero exit status

R.version
_
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 3
minor 6.1
year 2019
month 07
day 05
svn rev 76782
language R
version.string R version 3.6.1 (2019-07-05)
nickname Action of the Toes

`

Possible problems with output from the display command in a stata chunk

I think I notice that

  • a stata chunk with a single display command produces no output
  • a stata chunk starting with a blank line followed by a display command produces output as expected
  • a stata chunk starting with a display command followed by subsequent display commands omits the output from the first display command.

An example Rmd file is below - pdf output attached
stmd-test.pdf

I am not sure where the error is for these, and maybe there are 2 or more little errors.

I tried to investigate

  • at the end of stata_engine(), I included a
    print(knitr::engine_output(options, options$code, out))
    and that looks ok to me.

  • when I include a print(x) at the beginning of stataoutputhook() there looks to be an issue relating to how character strings are parsed/joined, maybe because the display output includes string quotes.

  • I also wondered if there was a second small error for the loss of the single/first line, and was wondering if the firsttext code has a problem because I see the warning

Warning messages:
1: In min(grep("[[:alnum:]]", y)) :
  no non-missing arguments to min; returning Inf

I have Stata 15.1 (but don't think this is anything to do with the Stata version).

Sorry I can't propose fixes.

Example Rmd file code

---
title: "display command output examples"
output: pdf_document
---

```{r setup}
# remotes::install_github("hemken/statamarkdown")
library(Statamarkdown)
library(sessioninfo)
```

Output for this chunk is missing
```{stata}
display "Hello 1"
```

Output correctly displayed with the first blank line removed
```{stata}

di "Hello 2"
```

Output from the first command omitted
```{stata}
di "Hello 3"
di "Hello 4"
```

Checking if these occur without the use of string quotes in the command

```{stata}
display 1
```

```{stata}

di 2
```

```{stata}
di 3
di 4
```

```{r}
sessioninfo::session_info()
```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.