Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cells with more than one command echo back all the commands #4

Open
ideabucket opened this issue Aug 11, 2022 · 6 comments
Open

Cells with more than one command echo back all the commands #4

ideabucket opened this issue Aug 11, 2022 · 6 comments

Comments

@ideabucket
Copy link
Contributor

ideabucket commented Aug 11, 2022

Thanks so much for writing this!

If you have a cell that contains more than one command, the output from Stata contains the full console, including each command. For example, here's what you get if you run two commands from one cell:

sysuse auto
tab foreign rep78
. sysuse auto
(1978 automobile data)

. tab foreign rep78

           |                   Repair record 1978
Car origin |         1          2          3          4          5 |     Total
-----------+-------------------------------------------------------+----------
  Domestic |         2          8         27          9          2 |        48 
   Foreign |         0          0          3          9          9 |        21 
-----------+-------------------------------------------------------+----------
     Total |         2          8         30         18         11 |        69 

. 

But if you break up the commands to one per cell you don't get the echo:

sysuse auto
(1978 automobile data)
tab foreign rep78
           |                   Repair record 1978
Car origin |         1          2          3          4          5 |     Total
-----------+-------------------------------------------------------+----------
  Domestic |         2          8         27          9          2 |        48 
   Foreign |         0          0          3          9          9 |        21 
-----------+-------------------------------------------------------+----------
     Total |         2          8         30         18         11 |        69 

Based on the documentation for pystata.stata.run it looks like the way to fix this is to wrap what's passed as its code parameter in """, which will make Stata treat the cell like a do-file.

I'd write a PR for this but I don't know Python. Sorry!

@ticoneva
Copy link
Owner

I have added a new option echo. Setting it to True in the configuration file should give you the desired effect.

  1. Install the latest version:
pip install git+https://github.com/ticoneva/pystata-kernel.git
  1. Create a configuration file during installation:
python -m pystata-kernel.install --conf-file
  1. Set echo to True in the configuration file:
[pystata-kernel]
...
echo = True

Let me know if it works or not.

@ideabucket
Copy link
Contributor Author

ideabucket commented Aug 12, 2022

Thanks for the quick response—this produces consistent behaviour, in that all cells now echo back the command, but it's the opposite of what I wanted. I'd like to suppress the echo in multi-command cells (which was the stata_kernel behaviour). In other words:

sysuse auto
tab foreign rep78
(1978 Automobile Data)


    Repair |
    Record |       Car type
      1978 |  Domestic    Foreign |     Total
-----------+----------------------+----------
         1 |         2          0 |         2 
         2 |         8          0 |         8 
         3 |        27          3 |        30 
         4 |         9          9 |        18 
         5 |         2          9 |        11 
-----------+----------------------+----------
     Total |        48         21 |        69 

@ticoneva
Copy link
Owner

Unfortunately, there appears to be no way to do that directly through pystata—or Stata, for that matter. The workaround is to use a combination of quietly and noisily:

quietly {
  noisily: sysuse auto
  noisily: tab foreign rep 78 
}

@ticoneva
Copy link
Owner

I spoke too soon. There is a way and it will be incorporated in the next version.

@ticoneva ticoneva reopened this Aug 15, 2022
@ticoneva
Copy link
Owner

ticoneva commented Aug 15, 2022

Version 0.1.20 accepts echo = None, which suppresses all commands.

@ticoneva
Copy link
Owner

Handling multi-line commands requires porting stata_kernel's CodeManager class with significant changes. Since this will take significant effort, I am removing this feature until it actually works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants