DataSpell - save state like in RStudio? - jupyter-notebook

Is it possible to save the Jupyter variables in DataSpell similar to how this works in RStudio?
At the moment, after I closed DS, I need to recompute everything. Of course I can write the main variables to disk myself, but I don't want to do that for all variables all the time.

I think the closest thing to the save/load workspace behavior in RStudio is the %store magic. IPython provides the %store magic, but %store is available in Jupyter Notebooks in DataSpell.
Here is the %store documentation: https://ipython.readthedocs.io/en/stable/config/extensions/storemagic.html

Related

Autoformat code in a jupyter notebook with a keystroke

Is there a widget or keyboard shortcut to apply code formatting a jupyter notebook?
If I have a function like:
def f(x):
y = x*2
z = y*2
return z
I'd like to be able to autotab this function over to:
def f(x):
y = x*2
z = y *2
return z
automatically.
There's jupyter-black - a simple extension for Jupyter Notebook and Jupyter Lab to beautify Python code automatically using Black
For JupyterLab, there's also JupyterLab_Black.
For JupyterLab, there's jupyterlab_code_formatter - a JupyterLab plugin to facilitate invocation of code formatters. You can configure the keyboard shortcut for that.
Keep in mind that soon (present is Fall 2022) the document-centric notebook experience, most people now associate with the classic notebook interface, will be based on what is underlying JupyterLab, see here. And thus investing great time working out things in the old classic notebook may result in you needing to change approaches soon as a lot of the stuff that works only with the classic Jupyter notebook interface will need updating to use while things already working in current JupyterLab will either work or have a lot less friction getting updated.
There is Jupyter Nbextensions Configurator which contains several extensions for your Jupiter Notebook needs:
autopep8;
Code prettify.
You'll find instructions on how to set them up in links.
Both of extensions have their settable toolbar buttons and are applicable to a whole document.

Call notebook using R in Databricks

I have a R notebook in Databricks, that I want to call inside an other R notebook.
I know that to call the notebook_a, one should do :
%run /path/notebook_a
But I want to do it inside an R script. For example :
if(condition){ %run /path/notebook_a }
Of course this code does not work.
Thanks a lot.
You should be able to use dbutils.notebooks.run for calling another notebook, but there is a difference between it and %run:
dbutils.notebooks.run executes another notebook as a separate job, so no definitions, etc. is pulled into the context of the current notebook - you can communicated data via temp views, etc.
%run execute another notebook and pulls all definitions and sides effects into the context of the current notebook.
I'm not sure if dbutils.notebooks.run will help in your case.
P.S. I personally would recommend to use %run with notebooks that only define functions, not doing any calculations, etc. - in this case, even if you have %run this doesn't cause any side effect on your current context.

Atom and Hydrogen: Output and console

I'm a Python beginner and recently came across the Atom editor and the package Hydrogen, that implements the Jupyter notebook. I did so after realizing that running the notebook in Chrome consumed way too many resources and also seemed to be a bit slower.
However, the Atom editor and Hydrogen always output prints within a little frame in the code (see image). Unfortunately, it doesn't use the full window width. I also don't see any console/terminal for installing pip libraries.
Is there a way to have the output in a console below the code, just as in Jupyter, and to have a terminal?
this comes most certainly too late, but in case someone else searches for this:
hit control+shift+P / cmd+shift+P and type "toggle output area".

Rgui command-line for sourcing R file

What command line option to use behind Rgui.exe for immediately sourcing an R source file? Instead of having to type source("c:\MyGreatSource.R") manually afterwards. Something like:
Rgui.exe --source "c:\MyGreatSource.R"
Sounds like a simple question answered in any beginner's manual, but I couldn't find such an option anywhere.
I found a workable solution, maybe others are interested. Again, what I like to do is to start the Rgui and work there. All my work environment and functions are defined in an R source file, which I constantly develop further during working. So each of my commands in the GUI starts with Load1(); where Load1 is a function which simply sources my R file, to update the changes I have just made. Obviously, Load1 is also defined in my R file, so I need to get it in the first place, without much effort. I have set the command-line options for neither loading nor saving the workplace; I don't like my old mess from the previous session with test variables and so.
However, my solution now is to just create a workplace RData file which only contains the definition of my Load1 function. This workplace file is easily loaded at every start by just adding its path into the command-line options "D:\MyLoad1.RData"
I use a AutoHotkey Script
run,C:\Program Files\R\R-3.3.3\bin\x64\Rgui.exe
WinWait,RGui (64-bit)
WinWaitActive,RGui (64-bit)
Sleep 100
Send,source("%1%")
Send,{enter}

ESS and RScript : Executing in style of `compile-dwim-run'

I just got ESS set up in EMACS (I'm a relative newbie in this area). I have figured out how to take an R script and fire up an interactive R shell and evaluate a whole buffer ("C-c C-b"). But I'd also like to have the ability to submit an R script via RScript in the way that you can with Perl or Python with `compile-dwim-run', which I have bound to "C-c r", and have the whole output returned to me in a separate buffer without keeping open an interactive R shell.
I can't seem to find a default way to do this, and I'd like to leverage whatever ESS has to work that (I assume there is) before I go off and attempt to roll my own.
Thank you,
Matt
C-c C-l is what you are looking for? Use C-c C-h to see all the keys that are bound on C-c map (an even better approach is to install helm-descrbind from emacs package manager - you will be pleasantly surprised :).
[edit:] Sorry, misread your post slightly. You want batch evaluation. That is not available for R. The reason, the analysis in R is usually a complex process which you don't want to execute again and again. So you keep your interactive session open and iteratively achieve what you want.
There have been talks inside ESS to add some batch functionality, but it seems like very few people really need that.

Resources