How to create .jl file in IJulia - julia

I am very new to julia. I have just installed ipython and Ijulia. But every time I saved my file from ipython notebook, the format of the saved file is always .ipynb. I don't know if I can saved my file as .jl file. Or could anyone tell me how to create .jl file through ipython notebook. I have googled but seems like no one talks about it.

.ipynb is the JSON-based Jupyter notebook format, with conventions for storing code cells and associated metadata and data (such as inline images). Jupyter is designed as a fully-integrated interactive environment, not "just" a text editor, and as such the file format requires extra information. To create a .jl file, use a text editor or an ide such as Juno.

Related

Set Jupyter Lab working directory to the directory where Jupyter was started, not the parent directory of the notebook? [duplicate]

Question: How can one set the working directory of all notebooks opened in Jupyter Lab with a double-click, to be the project's folder, /myproject/, regardless of the notebook's subfolder within that parent folder? The working directory is identified by !pwd on Linux/Mac or !cd on Windows.
Context:
The Jupyter Lab sessions is initiated from the project's folder, by: /myproject/jupyter lab.
I am not looking for changing the working directory within the notebook with code (e.g. with !cd.. or using os), but change the settings of Jupyter Lab, such that the all kernels will start with the folder from where Jupyter Lab was initiated.
This is useful for being able to use consistent relative folders, regardless of the subfolder they are referred from. For example, for loading data in a specific subfolder.
I agree that this is often a preferred approach! I always have my notebooks configured to work like that because it:
makes it easy to specify paths to data and for outputs and
allows moving a notebook between directories without the need to change the paths
makes jupyterlab-lsp code intelligence work more reliably
I have a python module called make_paths_absolute.py with the following contents:
from os import chdir
from pathlib import Path
def make_paths_relative_to_root():
"""Always use the same, absolute (relative to root) paths
which makes moving the notebooks around easier.
"""
top_level = Path(__file__).parent
chdir(top_level)
make_paths_relative_to_root()
And in the first cell of every notebook, I add a line import make_paths_absolute. I like it this way because it makes it:
reproducible: anyone who copies/clones my project will be able to run the code without the need to customize anything in their Jupyter environment
work with all notebook interfaces (whether JupyterLab/RetroLab/classic Notebook)
is quite obvious for anyone reading the notebook that they should expect the paths to be absolute (=relative to the root).
To make that work you first need to set PYTHONPATH pointing to the root of the repository when starting JupyterLab. To do so on Linux/Mac you can prepend the jupyter lab command with:
PYTHONPATH=/path/to/your/lab/root:$PYTHONPATH jupyter lab
Alternatively, you can specify PYTHONPATH in kernel.json (either by modifying the default kernel specification or creating a copy of it first, see https://stackoverflow.com/a/53595397).
PS. The above is a simplification of my setup. In reality, I store make_paths_absolute.py in helpers package (so there is also an empty helpers/__init__.py and there is extra .parent) together with other initialization-time code, including a notebook called notebook_setup.ipynb which contains things like %matplotlib inline, pandas customizations (like making sure it uses stable sort), warning filters etc. So my every notebook starts with:
import helpers.make_paths_absolute
%run helpers/notebook_setup.ipynb
and I am really liking this setup working like that for two years now without any problems.
There is a feature request for making this easier at: https://github.com/jupyterlab/jupyterlab/issues/11619.
The most easiest solution in my opinion
Open Notepad
Paste the command "jupyter notebook --NotebookApp.iopub_data_rate_limit=1.0e10"
Save the notepad file with an extension of ".bat" instead of ".txt"
Paste the file in which directory you want to initialize your jupyter
Double click and open the ".bat" file
Jupyter opens with desired directory as base
This way you control the jupyter root directory as and when required and don't
really have to perform any manual settings
Hope this helps
".bat" file created on Desktop
enter image description here
".bat" file double clicked and executed
enter image description here
jupyter opens with Desktop as the intended base directory
enter image description here

R files with Jupyter lab

I have just started to run the R kernel with Jupyter lab. How can I can import existing .R files into a jupyter notebook.
Also I can I save a .jpynb notebook back to .R if needed?
Rgs
CCR
I suppose a source("filename.R") function could help.
Following R Documentation it
"..causes R to accept its input from the named file or URL or connection or expressions directly. Input is read and parsed from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment".
Applying some parameters like echo, keep.source, local etc. to the function also seems useful.
Good luck!
P.S. I have no idea yet how to save .ipynb back to .R files

RStudio: Running .Rprofile in source file location

I have set up a workflow governed by a Makefile.
Under code/ I have multiple *.r scripts each typically responsible for creating one output file (typically an RData file but could also be csv exports or png images, any file in principle)
code/.Rprofile contains some helper functions to bootstrap the whole project directory system and sources some helper functions etc.
The scripts in code/ need this functionality to work properly.
RStudio has the convenient menu entry to set working directory to source file location.
But could I also make it run .Rprofile in that directory if found? Or really just start R a fresh from the directory of the source file?

How can I ask jupyter to automatically revert when file has changed on disk

Hello I am using jupyter-lab with the jupytext extension.
This extension allows you to --sync different format so that you can edit say a Rmd file that will automatically be converted to ipynb
This ipynb file is loaded in jupyter
To update the file opened in jupyter I have to click on "save", I then get the following message
I then have to click on revert to update from disk.
Is there a way so that the file on disk is automatically "reloaded" each time it changed or say every second and that It s "reverted" automatically ?

Command Line to Open .py with IPython

I would like to use the great IPython Web Interface to open, evaluate, edit and save the following "myfile.py" (see below) avoiding the annoying process: Create an .ipynb > import myfile.py to it > make some evaluation or edition > export to .py > remove unnecessary code lines and finaly get again the following content (myfile.py):
import os
# <codecell>
# Number division
print(4/5)
# Number Plus
print(1+40)
Is there a command line to do so?
Notes:
I want work ONLY with .py files, any solution with store/work with .ipynb (JSON files) not be welcome.
Suggestions for other programs will be very welcome.
On stable version, use the --script flag, it always save .py file wihthout having to go through the export process. Still it also save the .ipynb file along side.
On dev version there are now pre-save hook that allows you to do whatever you want for saving .
To automatically load .py files, you will have to write your own Notebook File Loader backend that accept .py files.

Resources