Jupyter still showing removed print statements in pycharm - jupyter-notebook

After commenting out print statements in an included file, the data from the old print statements are still shown even if I delete the cell.

The solution was to exit the notebook file and open it again and re-run the cells. Also, you can clear all outputs as shown here :
https://youtrack.jetbrains.com/issue/PY-51862/Feature-Request-Add-clear-all-outputs-to-Jupyter-Notebook
by pressing double shift and then searching for "Clear Outputs", but for me that didn't prevent the old print statements from still being displayed.

Related

My R script has been turned entirely into blank spaces. Is this recoverable?

If I knew how to reproduce this then I would, but I have never encountered this before. I saved my work using RStudio as I normally would, saving the progress of writing my R script. But when I opened it the next day, the entire script has been blanked. It still has the same file size as before, but nothing appears when I open it in RStudio. It just has a blank line 1.
If I open the script in Notepad++ I can see that the entire file has NUL characters. What has happened here? Is this recoverable?

Control print to cell in Jupyter Notebook

Is there any way or magic word that can direct the code to print to specific location (output below the cells or console). I'm imagining something like below.
The reason I'm asking is, I have a sets of asynchronous co-routine started running from jupypter notebook, which constantly print some output to show the result which I want them constantly showing in the console. Meanwhile I want to using jupyter notebook to see some of object for debugging, and I only want to print some values in the cell output.
%print_here
print('hello')
%print_to_console
print('hello')

Jupyter Notebook cell stopped working as such

There is the first cell that is supposed to execute code as the rest, but somehow it's not even working at all.
The next cells are working properly, but this forst one doesn't recognize my input.
In the pictures provided you can see that the next cell recognizes my input as code and highlights the proper words in color. When I first opened the notebook it was alright, but it just stopped working for this first cell.
I have tried to close and reopen, interrupt kernel and everything in my hands.
Thank you very much for your time.
Cell was not stuck on an infinite loop. Somehow Jupyter Notebook stopped recognizing it as a code cell. Therefore you have to manually srt it back to code cell. See image.

What cause format change when copy and paste in rstudio?

#sample select
sample_frac(mydata,n%)#random select n% sample
##############data review####
Just copy above code into rstudio script, you will find 2 more tab added to the last line.
What cause it?
Edit
As mentioned by #Jay in the comments, the n% in the command is treated as a function and since it is not complete it indents the next line.
To further confirm, try with df %in% in the script or df >%> and hit enter to see the cursor goes to the next line with an indent.
To avoid that just complete the function there.
sample_frac(mydata,n)
OR
sample_frac(mydata, n %% somenumber)
whatever you are trying to do and it should be fine.
Original Answer
It did add 2 tab spaces in the code when pasting in the RStudio script. I tried to paste the same text in my notes, Pycharm editor but it did not add any extra tabs there. So it was sure that this is a RStudio issue.
It turns out it is the indentation settings in RStudio which is responsible for this. To change that:
Go to Tools -> Global Options. Click on the Code option on the left. You'll see this :
Uncheck Auto-indent code after paste
and click on OK.
Now try to paste the same text. Should be resolved.

How to load a notebook without the outputs?

I mistakenly printed to much to the output during a single cell's execution and now the browser tab completely freezes every time that notebook is opened. I tried restarting ipython and it didn't help (I am guessing that each time it is loaded, also all the chunk of text is loaded with it).
Is there a way to load a notebook with outputs suspended or clear?
One hack if you're desperate: open the .ipynb file, which is a text file. Scroll down to the lengthy cell output and delete it. Of course, you need to be careful that the result is still a valid .ipynb file.
nbstripout is a simple tool that removes all output from a notebook (without needing to open the notebook in your browser).
your code will be saved in the form of JSON. open it with json viewer and carefully delete the unwanted output cell and save it back.

Resources