Is there a built-in command in Julia Pkg to switch the selected environment? - julia

The Julia Pkg documentation tells how to initiate an environment ($ activate $ENV-NAME), but it probably lacks the handy command to switch to the already created special environment. Also, I'm having trouble finding a command that shows all already created environments on the list, hence, if I have forgotten the names of the environments previously created, I need to do a manual search through the Julia-related folders...
So far, the verbatim help command in Julia REPL provides a poor description and so does the related Pkg-documentation webpage.
Another possible general answer to this predicament is to start using the Playground.jl module, which was recommended here on Medium:
However, the direct download attempt with Pkg repeatedly fails since the Pkg isn't able to find the package in the suggested GH project.
Thanks beforehand for any recommendations.

In package manager prompt just type activate # and press tab-key. The REPLs autocomplete will show you the possible environments.

If you are on a Mac or Linux
you can run this shell command to find all the "enviroment"
bash-3.2$ pwd
/Users/ssiew/juliascript
bash-3.2$ find . -name Project.toml
./Luxordir/Project.toml
./symata/Project.toml

Related

Activating Julia virtual environments

I'm trying to figure out how Julia packages work since I like having containerized environments. I'm really struggling with it.
In python, I'd do something like conda create env --name ds to make an environment and then to install containerized packages I'd use conda activate ds; conda install <packages>.
I'm not having much success trying to get Julia to make a virtual environment.
From the Julia REPL I can type ] to go to package managers then I can create an enviornment with activate ds. From here I can add important packages add IJulia DataFrames Plots
At this point, my environment becomes actual folders which is good.
What I then don't know how to do is to activate my environment so that I can then run using IJulia; notebook()
From the REPL if I type activate ds it doesn't know what I'm talking about, even if I do cd("ds"); activate . it still doesn't know what I'm trying to do...
I looked at the docs and it seems to detail out how to manipulate packages but I haven't found anything helpful for actually running them.
You have to write activate ds (or activate . if you are already in the ds directory) in the package manager mode that is started with ] as you have commented.
Alternatively you can activate environments when you start Julia. Just write
julia --project=.
(if you are already in the ds directory).
Here https://github.com/bkamins/PyDataGlobal2020 you have a step by step example how to run things for a sample project.
A third option is to activate the environment via the package manager API e.g. like this
using Pkg
Pkg.activate(".")

How to search completion list in zsh just like fish shell?

In fish shell, I can use Shift+Tab to search completion list. But I don't know how to do that in zsh.
I think what you're looking for is additional functionality from zsh-users called zsh-completions.
I've just started using this, and since I also have Homebrew, I was able to install it easily with brew install zsh zsh-completions. But the linked resource has many installation options and instructions.
When you're done installing you should probably run source ~/.zshrc and then you should see the effects.

Why do which and Sys.which return different paths?

I tried to run a Python script from R with:
system('python script.py arg1 arg2')
And got an error:
ImportError: No module named pandas
This was a bit of a surprise since the script was working from the terminal as expected. Having encountered this type of issue before (with knitr, whence the engine.path chunk option), I know to check:
Sys.which('python')
# python
# "/usr/bin/python"
And compare it to the command line:
$ which python
# /Users/michael.chirico/anaconda2/bin/python
(i.e., the error arises because I have pandas installed for the anaconda distribution, though TBH I don't know why I have a different distribution)
Hence I can fix my issue by running:
system('/Users/michael.chirico/anaconda2/bin/python script.py arg1 arg2')
My question is two-fold:
How does R's system/Sys.which find a different python than my terminal?
How can I fix this besides writing out the full binary path each time?
I read ?Sys.which for some hints, but to no avail. In particular, ?Sys.which suggests Sys.which is using which:
This is an interface to the system command which
This is clearly (?) untrue; to be sure, I checked Sys.which('which') and which which to confirm both are pointing to /usr/bin/which (goaded on by this tidbit):
On a Unix-alike the full path to which (usually /usr/bin/which) is found when R is installed.
To the latter, on a whim I tried Sys.setenv(python = '/Users/michael.chirico/anaconda2/bin/python') to no avail.
As some of the comments hint, this is a problem that arises because the PATH environment variable is different for programs launched by Finder (or the Dock) than it is in the Terminal. There are ways to set the PATH for Dock-launched applications, but they aren't pretty. Here's a place to start looking if you want to go that route:
https://apple.stackexchange.com/questions/51677/how-to-set-path-for-finder-launched-applications
The other thing you can do, which is probably more straightforward, is tell R to set the PATH variable when it starts up, using Sys.setenv to add the path to your desired Python instance. You can do that for just one project, for your whole user account, or for the whole system, by placing the command in a .Rprofile file in the corresponding location. More information on how to do this here:
https://stat.ethz.ch/R-manual/R-devel/library/base/html/Startup.html

Running R from Mac OSX terminal

I've searched the web, and I'm still unclear on how to run R from the Mac terminal. I have Rstudio and the standalone R app installed. I thought I could just type "R" from the command line as I do with "python", but that doesn't work. Is it necessary to edit the PATH in my bash profile? If so, how do I give the correct location of R?
Thanks for any help
Edits after receiving comments
So, I'm running Sierra, and when I type "r" or "R" at the terminal, I get "-bash: R: command not found." If I type, "which R" in the terminal I do not get any output.
Here is the output from "echo $PATH": /usr/local/heroku/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/samuelcolon/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Users/samuelcolon/.rvm/gems/ruby-2.1.0/bin:/Users/samuelcolon/.rvm/gems/ruby-2.1.0#global/bin:/Users/samuelcolon/.rvm/rubies/ruby-2.1.0/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/samuelcolon/.rvm/bin:/Users/samuelcolon/.rvm/bin
As for the installation, I believe I downloaded it directly from cran.r-project.org a while ago. I can locate the GUI in my applications and open it--
I have version 3.13. Is it possible, I only have R.app installed but not R? Perhaps that's the reason I'm getting the 'command not found' when typing "R" into the terminal?
Generally, I've been working in RStudio, but I'd still like to access R from the terminal and also to find where things are located. I'm fine with removing and re-installing R if it's easiest to start from square one. I hope the extra detail helps, and I appreciate the responses.
An answer for those not that familiar with Terminal and Bash.
I have done a fresh update install of R from the R.org cran site as part of seeking an answer to your question.
I found this latest install version 3.4.0 installs R for access in Terminal, and also installs R.app as part of the package.
To my understanding, reading support docs, if you have an older version of R it will update that. However it will not update an installation of R installed by the anaconda package.
Where are the R files stored?
I can only assume that with a fresh install of the latest R, R will work for you in Terminal.
To learn where the R files are that are being accessed - in Terminal after starting R, and in R.app, type:
>R.home()
In my case as example:
In R.app - the R version 3.4.0 is accessed in the top directory (not my user folder):
R.home()
[1] "/Library/Frameworks/R.framework/Resources"
In Terminal - the R version 3.3.2 is accessed in the Anaconda package, again in the top level directory.
R.home()
[1] "/anaconda/lib/R"
So I have two different versions of R, and Terminal accesses a different version to R.app.
How can I ensure I access the same version in Terminal as I do in the R.app?
For someone familiar with bash, and how the whole bash command system works I am sure there is a well constructed command. All the same here are some novice solutions.
-
• First Solution:
I could update the anaconda version, however, I would prefer not to as as other elements of the anaconda package my depend on this older version of R. For those not yet familiar with Terminal and bash, not such a novice solution.
-
• Second Solution:
This solution came from mko. It provides a single use solution. From the result above, and checking the directory structure a little further to find this R file.
Finding the significant R file enables me to edit an extension of the above path shown in the R.app. So add /bin/R to enter
/Library/Frameworks/R.framework/Resources/bin/R
Entering and pressing return will start R from this version.
Alternatively, one can find this file and icon in the GUI Finder, lead by the above result, and just double click on it, and it will open Terminal and a session with R running for you. Easy!
One could also make an alias of it and put it on your desktop for easy future starts.
-
• Third Solution:
My last solution I think may be best, adding to mko's solution. Make an alias.
Being in my home directory in Terminal I open .bash_profile using the nano text editor. (If you do not already know how to do this, then best not use this solution.)
I then add the line in this env file.
alias Rv340='/Library/Frameworks/R.framework/Resources/bin/R'
I then save the changes and exit this terminal session. I then open a new Terminal window. (This is so the changes to the env above are incorporated in the new terminal session).
Then when I enter the alias:
Rv340
The version of R I want opens.
You can choose a different alias name to "Rv340".
-
• Fourth Solution:
A second more permanent solution for opening the same version of R in Terminal is as follows.
Copy the path as showing in R.app in response to the R.home() command above, and add that path to PATH in your .bash_profile. (If you do not know already how to do this, then ignore this solution.) Do so as follows.
export PATH="/Library/Frameworks/R.framework/Resources:$PATH"
To my understanding, this ensures that bash looks here for R (and anything else), then moves on to the other paths in PATH. Since this adds this path to the beginning of $PATH, an env variable, bash looks here first where it finds the newer version first, and stops looking.
When it comes to understanding PATH in the env set up in .bash_profile the following two links were helpful.
About PATH.
How to correctly add a path to PATH.
This solution may muck with anaconda's invocation of R. I have yet to check this.
First of all, you have to start terminal application. You can use either built in Terminal.app, or you can use replacement. My favorite one is iTerm2
https://www.iterm2.com
Then, you simply open terminal window and run R. Just like shown below:
Have fun with R!
Just ran into the same issue when installing R-4.0.3.pkg on my MacBook (MacOS BigSur). Can open R.app to the clunky R GUI, but typing in 'R' in terminal doesn't work.
Turns out, an R executable lives here: /Library/Frameworks/R.framework/Versions/4.0/Resources/bin/R
So I added this alias to my newly created .zshrc script:
alias R '/Library/Frameworks/R.framework/Versions/4.0/Resources/bin/R'
Now when I type in R, it opens... I swear this all happened seamlessly in earlier versions.
There is currently a bug in CRAN's R installation package that results in it not correctly installing symbolic links to R and Rscript for commandline use. I've just verified this by inspecting the postflight script in their 4.0.5 installation package. This only impacts MacOS system releases of 20 and above (you can check with uname -r).
I've included more info here, along with what the "correct" fix should be: manually creating symbolic links to /usr/local/bin that point to the R and Rscript binaries themselves. If this is the current challenge, then this would be a far better solution to creating aliases or manipulating PATH in various ways, since it's what the installation package intended to do (and presumably will again soon).
R: command not found
In short, if this is the problem, then Ashkan Mirzaee's answer (https://stackoverflow.com/a/67202173/2093929) to create the symbolic links directly is correct in form, but might not have the right link command. The 4.0.5 package intends instead to use:
mkdir -p /usr/local/bin
cd /usr/local/bin
rm -f R Rscript
ln -s /Library/Frameworks/R.framework/Resources/bin/R .
ln -s /Library/Frameworks/R.framework/Resources/bin/Rscript .
You can create a symbolic link from R and Rscript binaries to /usr/local/bin to add them to the PATH:
sudo ln -s /Library/Frameworks/R.framework/Versions/Current/Resources/bin/R /usr/local/bin
sudo ln -s /Library/Frameworks/R.framework/Versions/Current/Resources/bin/Rscript /usr/local/bin
Now which R should return /usr/local/bin/R and you can use R.
An easy way to open RStudio with admin privilege on macOS:
Go to Applications, then right click on RStudio
Select "Show Package Contents"
Go to Contents/MacOS
Now open terminal(in bash mode). Type sudo and drag the RStudio.exec into terminal and press on ENTER
Now RStudio will have admin access!

cygwin warning when building R package

I'm trying to build my own package using Windows. I installed everything I need, and running R CMD build mypackage and R CMD INSTALL mypackage seem to run fine. when I run the build command, though, I get a warning from cygwin:
cygwin warning:
MS-DOS style path detected: C:/Documents and Settings/e_sander/My Documents/mypackage_1.0.tar.gz
Preferred POSIX equivalent is: /cygdrive/c/Documents and Settings/e_sander/My Documents/mypackage_1.0.tar.gz
CYGWIN environment variable option "nodosfilewarning"turns off this warning. Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
I did go to the recommended website, but I don't know much about cygwin or linux so I'm not sure there's anything I need to do. I realize that using the MS-DOS style path is deprecated and not recommended in cygwin, but I'm not sure how to change that, since I'm running Windows and that's the path I need. I also haven't noticed any problems with my package, at least when I install it to my computer (and although I haven't used the tarball, I've opened it and everything looks fine). So here's what I'm trying to figure out:
Does leaving the path as is affect my package in any way?
If so, how could it adversely affect my package?
How do I change the path to make cygwin happy?
This is just a warning and it tells you how to disable it. It doesn't affect anything. If you want it to go away, run this from your shell:
export CYGWIN="nodosfilewarning"
Or you could mount C: to /c/ (see man mount).
Does leaving the path as is affect my package in any way?
- No, it is just a warning.
If so, how could it adversely affect my package?
- N/A
How do I change the path to make cygwin happy?
- Set the environment variable as the output states. There are multiple ways to do this; I chose to go with a solution that handles the issue across any invoked environment that parses or inherits from the windows environment by using the "Rapid Environment Editor" program to add a User Variable named CYGWIN with a value nodosfilewarning. But if you wanted you could add it through the control panel using Add environment variables for your account.

Resources