I am looking for a way to get the path of current working notebook on jupyter notebook irkernel in order to do setwd() easier.
Using reticulate and call python os does not work. Although it works in a python notebook.
library(reticulate)
os <- import("os")
os$listdir(".")
Related
As is indicated by the photos here, Pythons works just fine in my Jupyter Notebook, I can pip install, use packages and everything, but R doesn't. I used Anaconda to access the Jupyter notebook. How can I get R working just like Python does. Thanks
I wanted to ask how to repair kernel connection for R in jupyter notebook,
I am able to run R in Rstudio and python in jupyter notebook, I used to write R in jupyter notebook but after some updates(I dont know what updates) R stop working in jupyter notebook.
I would like to ask for some advices - I would like to run it without reinstalling it
I also folled some question on stackoverflow and on google but it was not helpfull.
I attached images of what errors it returns
I did try: $ conda install -c r r-irkernel
I have jupyter notebook installed, I also have R installed. Both work fine independently.
When I run jupyter with jupyter notebook, then try to open an ipynb file, I see
The only option in the dropdown is Python 3 (R is not an option).
Question
How do you open a jupyter notebook with an R kernel (on mac)?
Note
I tried jupyter notebook --runtime-dir /usr/local/bin/R but that was just guessing
Looks like the R kernel could be installed via pip?
Open any R session (e.g. in RStudio is fine, or open terminal/bash and type R to start an R session).
Install the kernel with:
install.packages("devtools")
devtools::install_github("IRkernel/IRkernel")
IRkernel::installspec()
Close and reopen the notebook and the R kernel will now be available.
If the R kernel does not appear as an option within a Jupyter notebook even after installing R, and one is using Anaconda, bringing up the conda prompt from the Start menu (Windows 10), and running the following commands may do the trick:
conda config --add channels r
conda install --yes r-irkernel
Credit to this post.
I use conda python environment. I start the Jupyter lab following the steps below:
$conda activate <env_name>
$jupyter lab --no-browser --port=8080 &
Now, from a jupyter lab notebook, when I try to import feather (import feather), it fails with Module Not Found message.
From the jupyter lab notebook, if I execute the following, it shows me that feather is present:
! conda list | grep feather
Now, if I shutdown Jupyter Lab in the same VM and start Jupyter Notebook instead, feather gets imported successfully from the notebook.
$conda activate <env_name>
$jupyter-notebook --no-browser --port=8080 &
I see this discussion, but don't see a solution there.
Alternatively, check your path from within your Jupyter notebook vs on the command line. I found that appending the module paths to sys.path solved this exact issue.
All of the ~/anaconda3/envs/[env]/lib/python3.7* paths were missing in my case.
I have found a possible work around to avoid this issue. This is based on this answer.
From the conda environment (e.g. my_env), I can create a new Python 3 kernel (say, python3_custom). Now, this kernel will be associated with all the libraries installed in that conda environment.
$ conda activate my_env
(my_env)$ conda install ipykernel
(my_env)$ ipython kernel install --user --name=python3_custom
(my_env)$ conda deactivate
I come out of my_env or base environment. Then I start JupyterLab from the command prompt:
jupyter lab --no-browser --port=8080 &
Once I open my notebook now, I can select the kernel as python3_custom. Since in the associated conda environment (my_env), feather is already installed, I don't get the error "Module Not Found" any more.
I recently installed the Anaconda3 distribution and I want to have the R and Julia Kernels available besides Python. I use windows 10.
To install IJulia I installed the Julia language and follewed the steps indicated in the IJulia page; everything went fine.
To install the R kernel I used the command conda install -c r r-essentials in the anaconda command prompt, again, no problems. I also installed R.
When I launch the notebook the only available kernel is Python, the R and Julia kernels doesn't appear in the list, I have no clue why this since I got no errors in the installation of IJulia and IRKernel. Anyone could help?
After a fresh installation of Anaconda Distribution (either 2 or 3), following steps should be performed to achieve the desired kernels (R & Julia) on your notebook.
To install R on Anaconda(2/3) Jupyter Notebook :
Open 'Anaconda Command Prompt' & execute conda update notebook to update your Jupyter notebook to the most recent version.
Then install IRkernel by conda install -c r notebook r-irkernel
Now you may open R in your command prompt by running R.exe
Install all necessary R packages using the following lines in the R console by executing :
install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ',
'devtools', 'uuid', 'digest'))
devtools::install_github('IRkernel/IRkernel')
Finally, make the R kernel available to your Jupyter Notebook by executing:
Install only for the current user ➡ IRkernel::installspec()
For System-wide installation(all Users) ➡ IRkernel::installspec(user = FALSE)
To install Julia on Anaconda(2/3) Jupyter Notebook :
First, download Julia version 0.4 or later and run the installer. Then run the Julia application (double-click on it); the Julia Console with a julia> prompt will appear.
Now, for the most important step, open 'Anaconda Command Prompt' & execute where jupyter to see the actual path of your Jupyter Notebook. The output will be something like "C:\Users\JohnDoe\AppData\Local\Continuum\Anaconda3\bin\jupyter.exe"
Copy the above location and go to your Julia console. Now, execute the following respectively:
ENV["JUPYTER"]="C:\\Users\\JohnDoe\\AppData\\Local\\Continuum\\Anaconda3\\bin\\jupyter.exe"
Pkg.add("IJulia")
Pkg.build("IJulia") (Optional, execute if further error occurs again.)
⬆ Notice that the backslashes have to be doubled when you type them as a Julia string. I've just assumed that the path is your Anaconda path with \bin\jupyter appended, but replace that with whatever where jupyter tells you.
After few minutes, in Julia console execute:
using IJulia
notebook()
Now, you can program Julia in your Anaconda Jupyter Notebook.
Excellent, it worked.
However, it is important to import the package first before adding it.
import Pkg; Pkg.add("IJulia")