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

Feature idea: Allow some code a block to be retained/uncommented #3

Open
jashapiro opened this issue May 31, 2020 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@jashapiro
Copy link
Member

While #2 addresses the idea of leaving comments in code block as a guide to people completing the notebook, sometimes it may be desirable to have some working code retained, or a skeleton of the working code included, and not commented out. To accomplish this, it may be nice to have a way to designate lines that should be retained.

learnr accomplishes something like this with separate solution blocks, but that seems too heavyweight for this application, and potentially allows drift between the exercise block and the solution.

In the Jupyter world, nbgrader instead uses specific comments to designate the start and end of a solution section, retaining the code outside those comments, and replacing only the code within the comments with a code stub:
### BEGIN SOLUTION and ### END SOLUTION. This solution has the advantage that the solved code chunk will run in the original document as a check that it is correct behaving as intended.

Under this scheme code of the following form:

### BEGIN SOLUTION
plot(data)
### END SOLUTION

would become:

### YOUR CODE HERE

or similar.

One other alternative is an indicator that a specific line should be replaced by commenting at the end of the line that would indicate that particular line should be replaced.

This could look like this:

plot(data) ### SOLUTION

to get the same result as above.

One other implementation might include a way to strip a commented line. Something like this:

### BEGIN SOLUTION
plot(data)
#> plot(<YOURDATA>)
### END SOLUTION

could turn into:

plot(<YOURDATA>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant