jupyter / help

:sparkles: Need some help or have some questions? Please visit our Discourse page.
https://discourse.jupyter.org
291 stars 97 forks source link

"Restart & Clear Output/Run All" does not reset variables in R. #351

Open regmeg opened 6 years ago

regmeg commented 6 years ago

Hi,

It seems like R notebooks don't get their variables reset after the Restart commands are run.

It's very simply to reproduce, firstly define a variable and print the defined variables:

a <- 3  
ls()

then remove the variable definition and simply print out the defined variables by running "Restart & Run All" or "Restart/Restart & Clear Output" and running the cell with: ls()

I've done a similar experiment with a python notebook and seems to be working OK.

I'm running my notebook server from the Anaconda Prompt on Windows 10, version outputs from the prompt:

conda list anaconda

Name Version Build Channel anaconda 5.1.0 py36_2 anaconda-client 1.6.9 py36_0 anaconda-navigator 1.7.0 py36_0 anaconda-project 0.8.2 py36hfad2e28_0

conda list R

Name Version Build Channel r-crayon 1.3.4 mro343h889e2dd_0 r r-digest 0.6.13 mro343h889e2dd_0 r r-evaluate 0.10.1 mro343h889e2dd_0 r r-irdisplay 0.4.4 mro343h889e2dd_0 r r-irkernel 0.8.11 mro343_0 r r-jsonlite 1.5 mro343_0 r r-magrittr 1.5 mro343h889e2dd_0 r r-pbdzmq 0.2_6 mro343h889e2dd_0 r r-r6 2.2.2 mro343_0 r r-repr 0.12.0 mro343h889e2dd_0 r r-stringi 1.1.6 mro343h889e2dd_0 r r-stringr 1.2.0 mro343h889e2dd_0 r r-uuid 0.1_2 mro343h889e2dd_0 r

conda list jupyer

Name Version Build Channel jupyter 1.0.0 py36_4 jupyter_client 5.2.2 py36_0 jupyter_console 5.2.0 py36h6d89b47_1 jupyter_core 4.4.0 py36h56e9d50_0 jupyterlab 0.31.4 py36_0 jupyterlab_launcher 0.10.2 py36_0

This is kind of small bug, but can lead to some very serious miscalculations in a notebook.

Thanks, Rihards

takluyver commented 6 years ago

Is it possible you've configured R to save and restore your namespace? Restarting the kernel really stops the kernel process and starts a new one, which we assume means a blank state, but it's possible for the language to restore variables if it wants to.

cc @flying-sheep

regmeg commented 6 years ago

@takluyver thanks for your reply.

No, I haven't done anything deliberate to save and reload the workspace data. I've done couple of more experiments:

  1. I've checked the folder that is given under getwd() for any .RData files, those were not present. Furthermore I've tried to run unlink("*.RData") and unlink(".RData") before running ls() but that did not change anything.
  2. I've run multiple notebooks in parallel and see if they share any workspace variables and that seems not to be case at all.
  3. The only way to reset the variables definitions is to run "Shutdown" and then do a "Restart".

So the only way to reset the variables without running rm(list = ls()) explicitly is to shutdown a kernel and then do a restart. It does not seem related to the R workspace.

takluyver commented 6 years ago

:confused: restart already does shut the kernel down and restart it. Maybe the issue is just that restart isn't doing anything for some reason? Is there any indication of anything happening when you press restart? Do the prompt numbers go back to In [1]: afterwards? Are there any messages in the terminal where you're running the notebook?

regmeg commented 6 years ago

That's actually a good spot - the prompt numbers dont go back toIn [1]:. As expected they they go to In [ ]: just after the restart, but when cells are being run again they keep incrementing. What could be the cause of that? That does not happen with python notebooks.

takluyver commented 6 years ago

That means that it's not actually doing the restart. Look in the terminal that you launched the notebook from, see if there are any error messages.

regmeg commented 6 years ago

That's what i get:

[I 09:13:46.746 NotebookApp] Starting buffering for 80e3d8c8-000c-455b-9014-927406373546:c7d54c89ca014873a912b56b6f4670e4
[I 09:13:51.845 NotebookApp] Kernel restarted: 80e3d8c8-000c-455b-9014-927406373546
[I 09:13:51.888 NotebookApp] Adapting to protocol v5.0 for kernel 80e3d8c8-000c-455b-9014-927406373546
[I 09:13:51.890 NotebookApp] Restoring connection for 80e3d8c8-000c-455b-9014-927406373546:c7d54c89ca014873a912b56b6f4670e4
[I 09:13:51.893 NotebookApp] Replaying 2 buffered messages
R_zmq_bind errno: 100 strerror: Address in use
R_zmq_bind errno: 100 strerror: Address in use
R_zmq_bind errno: 100 strerror: Address in use
R_zmq_bind errno: 100 strerror: Address in use
R_zmq_bind errno: 100 strerror: Address in use

I'm not exactly sure which address does it complain about. There's no stack trace or anything. I've tried to run the notebook with different ports, but that does not seem to be the issue.

These guys seems to have had similar issues: https://github.com/jupyter-incubator/enterprise_gateway/issues/8

Thanks

takluyver commented 6 years ago

That sounds like it's trying to start the new kernel but it hasn't shut down the old one. @flying-sheep, have you come across anything like this?

flying-sheep commented 6 years ago

nope, never. sorry!

kalenkovich commented 6 years ago

I get exactly the same error.

tmcphail2 commented 6 years ago

I also had this same error and in my case was able to narrow the issue down to ".RData" and ".Rhistory" files that I had created using R Studio and saved in a directory. When I use Jupyter Notebook to create a new "R notebook" in THAT folder that contains the RData file the new notebook inherits the data in the .RData file. If I create a new R notebook in a different directory with no .RData file or delete the existing .RData file and create a new notebook in that directory, no inherited variables.