How to permanently change the default working path of julia? - julia

I was able to temporarily change it with the following command, but after reboot the working path still changes to C drive.
cd("D:\\jl files”)

As it is explained in the Julia Manual Getting Started section the simplest thing to do is to add the:
cd("D:\\jl files")
line to your ~/.julia/config/startup.jl file (this is a Linux path; if the file does not exist then you should create it with this single line). Since you are on Windows then ~ part should be replaced by default is your user profile folder (it should be possible to check it with ENV["USERPROFILE"] command in Julia). However, if you have a custom installation the .julia folder can be placed in some other folder so you need to check it on your system.

Related

Where should I set the variable PATH in R?

I constantly need to call Tex Live binaries for compilation in R. However after the upgrade of Tex Live distribution, the path to current binaries needed to updated manually in the PATH(Sys.getenv("PATH")) variable.
As a single user on a Ubuntu system, which file should I update the value in, so that R gets the PATH correctly irrespective of whichever directory R is launched from.
One point I still don't gather is from where does R gets its site-wide (I mean for all users, even if faulty in saying so) PATH variable set, because no such variable name as "PATH" occur inside any files (Renviron, Renviron.site, Rprofile.site) in either of "R_HOME/etc/" and user's home directory? I also haven't set Sys.getenv("R_ENVIRON") and Sys.getenv("R_ENVIRON_USER") values.
I'd appreciate anybody's input here.
#JeffreyGoldberg's solution was close, but not quite right.
Rprofile files are interpreted as R code
Renviron files can only contain name value pairs, and are not interpreted as R code
From the help for Startup:
Note that there are two sorts of files used in startup: environment files which contain lists of environment variables to be set, and profile files which contain R code.
I'm not sure if this question is asking specifically how one can set the site wide value of PATH, rather than PATH for one specific user, but there are three locations you can put these files.
A project directory (i.e., a directory you choose to launch R from)
HOME
R_HOME/etc
These locations are searched in the order numbered above. The first location can contain configurations specific to a project, the second contains those specific to a user, and the third, site wide configuration settings. When a file is found it is used, so local takes precedence over global. Don't think you can create a more specific version that simply updates what you've done in a more general configuration file. R_HOME/etc/Renviron is created on installation and should not be edited. You may create a file called R_HOME/etc/Renviron.site, but do not edit R_HOME/etc/Renviron.
To create a site wide value of PATH, you will want to set it in a file in R_HOME/etc. Here you can use either Renviron.site or Rprofile.site for the file name. For a file in R_HOME/etc, Do not use Renviron, Rprofile, .Renviron, or .Rprofile for the name of a profile or environment file in this location. You can find out what R_HOME is in an R session using R.home(), or Sys.getenv("R_HOME")
To create a PATH value for a single user, set it in a file in HOME, which you can find in your R session using Sys.getenv("HOME") or path.expand("~"). You can also just use "~" to refer to HOME. Here, an Renviron file should be ~/.Renvironand an Rprofile file ~/.Rprofile. Take note of the difference between how profile and environment files are named in your HOME directory vs. R_HOME/etc
To create a PATH for a single project, set it in a file in that project's top level directory. Name the files as you would in your home directory (.Rprofile or .Renviron).
If you are creating an Renviron file, the file should include the following line:
PATH=<your path>
< and > should not be included. An example would be:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
If you are creating an Rprofile file, the file should include the following line:
Sys.setenv("<your path>")
again, don't include "<" or ">". An example would be:
Sys.setenv("/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin")
There are various ways of doing this that get and edit a PATH variable (e.g., tack on a new path at the end, or the beginning). You can also use the strategy of setting an environment variable if it doesn't already exist and/or doesn't contain something you want it to. I've come to prefer just setting up my path simply, and coding it directly.
One final note, if you run R from a command line interface, environment variables may be inherited from your shell. RStudio also has its own startup sequence and may modify the end of your PATH variable. It should start as it is defined in your Rprofile or Renviron files. The R Console app itself has the fewest quirks with system environment variables, and should accept your path exactly as it is set with an Rprofile or Renviron file.
Edit: I should have tested before posting. What I describe below did not work. (Down voting my own answer is a strange thing.)
On my system (macOS, bash), R.app is not picking up my $PATH from my shell environment or .profile. However RStudio is picking it up. I do not understand the different behaviors.
One way to get consistent behavior would be to specify this in an Renviron file.
If you create a file named .Renviron in your come directory with a line like
Sys.setenv(PATH="/opt/local/bin:usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin")
(but of course with the path elements you need) that should give you consistent behavior.
The downside is that you need to manually maintain this. I suppose you could run a script from one of your other start up scripts that generated the .Renviron file. But either way, I consider this whole thing a work around in place of actually understanding where R picks up its environment from.

How to permanently set fix my working dir?

Every time I restart R I issue the following command:
setwd("C:/Users/avtarsingh/Downloads")
How do make this my permanent working dir
Create a file called ".Rprofile" and add that command. R will look for this file every time it starts and change to that directory accordingly. More info in the R documentation here
In order to change your working directory permanently, you can find the following file “Rprofile.site” that is located in your installation path “etc” folder and open it in your favorite text editor (i.e., VSCode). Then you can add your permeant working directory to the first line, like the following line of code:
setwd(“C:\your permeant working directory”)
and save it. Next time you open the R-CRAN, your working directory is set to what you have saved.
Any code which you wish to run every R session can be added to Rprofile.site.
On a Windows machine, this file is located for example in C:\Program Files\R\R-3.1.2\etc. On Windows you will need to run your favourite text editor as an administrator to make changes to this file, since it is in Program Files.
This is also a good place to set your local CRAN repository, etc.

Working directory error

I am working with PyCharm 4.04. Since I installed it, every time I open it, as default directory I get this:
C:\Users\Laura\AppData\Local\Temp\main.py1.tmp>cd
Which gives me an error when trying to use the console:
Error:Cannot start process, the path specified for working directory
is not a directory
But even if I change the directory, the message does not disappear.
The terminal, though, it does work and I can run projects, but I would like to use the console.
Another solution is to close the project, run rm -rf .idea and re-open it. Apparently Pycharm gets confused by some direct folder manipulation and doesn't reflect it properly in his .idea/*.xml files
I also got this error, and it got resolved by setting the default working directory. Follow the below path, and set the Working Directory to the folder where your code resides.
File > Settings > Build, Execution, Deployment > Console > Python Console > Working Directory ...
I finally solved the problem.
I think it all started because the first project that I opened with pycharm was in my "download" folder, so the working directory was automatically set to a temporal folder by default and allthough I moved the project to another folder and I manually changed the working directory from the terminal, it was not working.
The solution was creating a new project and giving a correct path to the new project. It seems very easy but it was not that obvious.
In the upper right corner click on small ▼ next to your main to run (look to the left from green right-pointing triangle)
Select Edit configurations.
In ▼ Python select the proper configuration name.
Look at the Configuration panel.
Fix items Script and Working directory.
pycharm
I had this same problem and just had to reinstall pycharm. It's a quickfix and I can't ensure it won't happen again.
I solved this by replacing all instances of the old filename and old directory with the new one in .idea/workspace.xml
It can be done with PyCharm running.
#user1068430 has the answer in the comments to the question:
When you open a project open the directory not a specific python file.
Instead of ~/Documents/myProject/main.py open ~/Documents/myProject
If you "open" the .py file then you'll have to set the working directory (File > Settings > Build, Execution, Deployment > Console > Python Console > Working Directory) every time. If you "open" the directory containing the .py file, then PyCharm will open and all of your .py files will be available in the left window. Select one of them and you're good to go.
i had the same issue, the error comes up when i want to upgrade my packages and when i run my project "this FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\youruser\AppData\Local\Temp\gen_py\3.7\__init__.py'" i found that the Temp file in C:\Users\youruser\AppData\Local was corrupt and it was fixed by deleting the "Temp" file, once deleted it will automatically create a new one with "gen_py" in it
To anyone with similar issues: Python interpreter virtual environment is where your python.exe sits. The working directory is where your script sits. To make everything easier, open a new project, scroll to location where you script is stored, and select. Click the interpreter option, click existing (if old one worked) or choose the python.exe. When asked, open the project in a new window, close old one to avoid confusion.
source = banging my head against the console for past few hours.
if the above mentioned solutions are not working, you can restart a new project.
file > New project...
then,
create a new project.

How to change .Rprofile location in RStudio

I am working with a "factory fresh" version of RStudio on Windows 7. R is installed under C:/Program Files which means the default libraries are stored here, and the two locations contained in .libPaths() on startup are both within this folder.
I want to work with another R library (igraph). Since the C:\Program Files folder is write-protected, I have set up another area to work in: C:\Users\nick\R and installed the igraph library in C:\Users\nick\R\library. I can manually add this location to the .libPaths() variable and use the library with no problems.
However, my problem is getting RStudio to automatically add this location to the .libPaths() variable on startup. I read that I could add the relevant command to my .Rprofile file - but I couldn't find any such file (presumably they are not automatically created when RStudio is installed). I then created a file called .Rprofile containing only this command. This only seemed to work when the .Rprofile file was saved in C:\Users\nick\Documents (which is the path stored in both the R_USER and HOME environmental variables). What I would like is to have the .Rprofile file stored in C:\Users\nick\R.
I have read all the information in ?Startup and it talks about where to store commands that run on startup. But I just can't make this work. For example there seems to be no way to change the location of the home directory without reading a file stored in the home directory. I don't seem to have any .Renviron files and creating these myself doesn't seem to work either.
I would really appreciate an answer in simple terms that explains how I could go about changing where the .Rprofile file is read from.
In Windows, you set the R_USER profile by opening up a command line and running:
SETX R_PROFILE_USER "C:/.../.Rprofile"
Where (obviously) the path is the path to your desired .Rpofile. In R, you can check that it worked:
Sys.getenv("R_PROFILE_USER")
Should return the path you specified. Note that you likely need to have all R sessions closed before setting the R_USER variable.

Problem in creating text file(Qt application) in installation directory (using CMake to install)

I am new to programming. I am creating a small word jumble game to practice qt programming. In this application I am creating a text file (score.txt) to keep score of player. I have done this by:
QFile scoreFile("score.txt");
if (QFile::exists("score.txt"))
{
scoreFile.open(QIODevice::ReadWrite | QIODevice::Text)
// and update the score.
}
else
{
scoreFile.open(QIODevice::ReadWrite | QIODevice::Text);//create score file
//and write the score to it.
}
this code is working good here. Now I am using CMake to build and install generated binary (I am working on Ubuntu) using this code:
#set project name, version and build code here.
install(TARGETS wordJumbleGame DESTINATION bin)
I build project in /home/myname/project/build/
My source code is in /home/myname/project/src/
CMakeLists.txt is in /home/myname/project/CMakeLists.txt
I installed program using make install.
Till here all things working fine. But now problem is that when I run this program (I run it from terminal giving command wordJumbleGame) It creates score.txt in /home/myname/project/build directory. It is not being created in installation dir bin.
So please help me out, what am I doing wrong. And please also tell me how do I make my program to appear in application->game lists so I can run it from there not from command prompt.
Unless you prefix it with a slash (on unix) or a drive path (Windows), QFile's constructor parameter is a relative path - relative to the current working directory. score.txt is created in the build/ directory because that's probably where you're executing the binary from.
You can't store score.txt in the /usr/bin directory because, typically, you can't write there without root privileges.
What you want to do is get a path to some directory where you can store your score.txt file. To do that, you can use the QDesktopServices class. That will give you directory information on a per-user basis. Here's an example:
#include <QDesktopServices>
// this would go in main(), probably
QCoreApplication::setApplicationName( "word jumble game" );
// now when you want to read/write the scores file:
QString dataPath = QDesktopService::storageLocation( QDesktopService::DataLocation );
QFile scoreFile( dataPath + "score.txt" );
// on my system, this produces: "/home/adam/.local/share/data/word jumble game/score.txt"
// it will produce something similar for Windows and Mac too
You should set your appication name via QCoreApplication::setApplicationName before getting path information to keep the user data directory nice and organised.
As for getting your application in the games list, you'll need to create a menu entry that follows the freedesktop.org spec. I can't help you more with that, but this is a good starting point. Somebody else might have more info for you.
You need to create a .desktop entry file and install it using xdg-desktop-menu install. Here are two resources for you: freedesktop.org menu spec and adding .desktop files using CMake

Resources