Skip to content

Single- vs. multi-line code cells #23

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

Open
hugetim opened this issue Feb 23, 2023 · 2 comments
Open

Single- vs. multi-line code cells #23

hugetim opened this issue Feb 23, 2023 · 2 comments

Comments

@hugetim
Copy link
Contributor

hugetim commented Feb 23, 2023

Continuing the discussion from #16:

Preface

Using nbstata for my normal work a few times has turned up a few further quirks of pystata.stata.run.

By the way, nbstata's getting pretty complicated due to my stubborn insistence on the "noecho" mode, so it's really nice that pystata_kernel also exists, as a simpler kernel that passes each code cell pretty directly to pystata.stata.run. (Actually, if I were you, I would remove the echo=None config option to better keep things simple.) That way, if something unexpected happens, the user can at least trace the issue directly back to the behavior of pystata.stata.run.

Single- vs. multi-line code cells

Single-line input (to pystata.stata.run, and thus to pystata_kernel) is processed like Stata's interactive mode, whereas multi-line code is processed via running a do-file. This has a number of implications (beyond echo) that may be surprising to the unsuspecting user of pystata_kernel unless they read the fine print in the pystata docs linked above:

  1. Inline comments (// or /* ... */) work in multi-line code but trigger an error in single-line code.
  2. #delimit ; works in a multi-line code cell (only for that one cell--and I'd now suggest keeping it that way for pystata_kernel) but placing `#delimit ;' in a single-line cell will cause an error.
  3. More than one graph command in a cell will only result in one graph being displayed unless you give the additional graphs unique names. (This is only noted in the pystata docs for the %stata magic.)

edit: Contrary to my original assertions, there are no single- vs. multi-line issues with locals or the version command (and maybe no issues not already flagged somewhere in the pystata docs). The issues I was having with those turned out to only apply to the "noecho" mode which runs multi-line code as a program. (If you maintain that mode in pystata-kernel (contrary to my recommendation above), you may want to address those issues, though, perhaps just by acknowledging them in the README, for starters.)

@ticoneva
Copy link
Owner

ticoneva commented Mar 4, 2023

The 'noecho' mode is off by default, and stripping it out completely seems a bit excessive. Perhaps I can just add a note saying that this feature is incomplete?

@hugetim
Copy link
Contributor Author

hugetim commented Mar 4, 2023

Right, definitely. Maybe "experimental" is what I should have called it all along.

Sorry, rereading my post, it sounds more demanding than I was intending. My intention is just to be helpful in an informative way. It's no big deal either way. :)

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