Specify a Directory for Save in Mathematica - directory

Considering :
ALLdwafDif[#] & /# symmetries
Save["ALLL.m", ALLL]
Is there a way to save the results in a particular directory ? It automatically save the results in my user directory now.

The current working directory is given by Directory[]. You can set it by SetDirectory[]. Alternatively, you can append the directory name to ALLL.m and it works.
eg
f = 5;
Save["~/Desktop/temp.m", f]
does what you'd expect (~ is a shortcut for home directory on most Unices, and mma respects it, so this gets saved on my desktop)

If you want to change the default working directory permanently you can add something like SetDirectory["new_dir"]; to one of the files $BaseDirectory/Kernel/init.m or $UserBaseDirectory/Kernel/init.m (which one depends on whether you want to change the default directory for all users or for the current user only). Next time you restart Mathematica, Directory[] will then automatically be set to new_dir.

Save[SystemDialogInput["FileSave", "All.m"], ALLL]
brings up a standard system save-file dialog box and saves your file after you've chosen a location (and a new file name if you have chosen one).

I find it useful to save data in the same location as the notebook:
f = 5;
Save[FileNameJoin[{NotebookDirectory[], "f.dat"}], f]
Or to save in your (default) Dropbox directory:
Save[FileNameJoin[{$HomeDirectory, "Dropbox", "f.dat"}], f]
I rarely use the directory stack that's controlled by SetDirectory[] and friends.

Related

Return one folder above current directory in Julia

In Julia, I can get the current directory from
#__DIR__
For example, when I run the above in the "Current" folder, it gives me
"/Users/jtheath/Dropbox/Research/Projects/Coding/Current"
However, I want it to return one folder above the present folder; i.e.,
"/Users/jtheath/Dropbox/Research/Projects/Coding"
Is there an easy way to do this in a Julia script?
First, please note that #__DIR__ generally expands to the directory of the current source file (it does however return the current working directory if there are no source files involved, e.g when run from the REPL). In order to reliably get the current working directory, you should rather use pwd().
Now to your real question: I think the easiest way to get the path to the parent directory would be to simply use dirname:
julia> dirname("/Users/jtheath/Dropbox/Research/Projects/Coding/Current")
"/Users/jtheath/Dropbox/Research/Projects/Coding"
Note that AFAIU this only uses string manipulations, and does not care whether the paths involved actually exist in the filesystem (which is why the example above works on my system although I do not have the same filesystem structure as you). dirname is also relatively sensitive to the presence/absence of a trailing slash (which shouldn't be a problem if you feed it something that comes directly from pwd() or #__DIR__).
I sometimes also use something like this, in the hope that it might be more robust when I want to work with paths that actually exist in the filesystem:
julia> curdir = pwd()
"/home/francois"
julia> abspath(joinpath(curdir, ".."))
"/home/"

How to change to the next above directory

I really would like to know how to change directory to the next file, using 2 dots (/..).
I can go back to previous directory but how to do something like that to go to the next directory WITHOUT THE NAME OF THE FILE PLEASE!
I know it is possbile with the name of the folder but my answer is different, please let me know.
What O.S are you using? In linux ubuntu/Debian distributions (and probably in windows, not sure), you can enter the first child directory by simply typingcd */, this will change your current directory to the first child directory available in alphabetical order, example:
-/home
-alan
-desktop
-music
-alex
-documents
-pictures
-lisa
Assuming your in /home, if you write cd */ in the terminal you will be in /home/alan, because -alan is the first folder/directory available.

Sort (sorting) order of files in notebook list

How can I change the sort order of files in the notebook list? I would like it to be alphabetical for all file types and not case sensitive. Directories can appear before files or within the files.
Currently my list is sorted as follows:
- Directories (starting with upper case)
- directories (starting with lower case)
- IPython notebooks (starting with upper case)
- ipython noteooks (starting with lower case)
- Other files (starting with upper case)
- other files (staring with lower case)
I'm using Jupyter 3.0.0-f75fda4
just as an addition to the previous post:
edit ..\Anaconda\Lib\site-packages\notebook\static\tree\js\notebooklist.js for instance to sort last modified first:
this.sort_function = modified_sorter(0); // inserted
this.sort_id = 'last-modified'; // inserted
this.sort_direction = 0; // inserted
//this.sort_function = name_sorter(1);
// 0 => descending, 1 => ascending
//this.sort_id = 'sort-name';
//this.sort_direction = 1;
You will have to make the same changes to main.min.js in the same directory. Naturally, with every update of jupyter notebook this will be lost. Also, no guarantees as this is a quick and dirty fix.
EDIT: in case you have already created a virtual env make sure to do the same for ..\Anaconda\envs<venv>..
If you are handy with jQuery, you can edit IPython's static files and customize the "tree" page you are referring to.
On my Ubuntu machine I could manipulate the page by editing the file /usr/local/lib/python2.7/dist-packages/IPython/html/static/tree/js/notebooklist.js

How to create a new output file in R if a file with that name already exists?

I am trying to run an R-script file using windows task scheduler that runs it every two hours. What I am trying to do is gather some tweets through Twitter API and run a sentiment analysis that produces two graphs and saves it in a directory. The problem is, when the script is run again it replaces the already existing files with that name in the directory.
As an example, when I used the pdf("file") function, it ran fine for the first time as no file with that name already existED in the directory. Problem is I want the R-script to be running every other hour. So, I need some solution that creates a new file in the directory instead of replacing that file. Just like what happens when a file is downloaded multiple times from Google Chrome.
I'd just time-stamp the file name.
> filename = paste("output-",now(),sep="")
> filename
[1] "output-2014-08-21 16:02:45"
Use any of the standard date formatting functions to customise to taste - maybe you don't want spaces and colons in your file names:
> filename = paste("output-",format(Sys.time(), "%a-%b-%d-%H-%M-%S-%Y"),sep="")
> filename
[1] "output-Thu-Aug-21-16-03-30-2014"
If you want the behaviour of adding a number to the file name, then something like this:
serialNext = function(prefix){
if(!file.exists(prefix)){return(prefix)}
i=1
repeat {
f = paste(prefix,i,sep=".")
if(!file.exists(f)){return(f)}
i=i+1
}
}
Usage. First, "foo" doesn't exist, so it returns "foo":
> serialNext("foo")
[1] "foo"
Write a file called "foo":
> cat("fnord",file="foo")
Now it returns "foo.1":
> serialNext("foo")
[1] "foo.1"
Create that, then it returns "foo.2" and so on...
> cat("fnord",file="foo.1")
> serialNext("foo")
[1] "foo.2"
This kind of thing can break if more than one process might be writing a new file though - if both processes check at the same time there's a window of opportunity where both processes don't see "foo.2" and think they can both create it. The same thing will happen with timestamps if you have two processes trying to write new files at the same time.
Both these issues can be resolved by generating a random UUID and pasting that on the filename, otherwise you need something that's atomic at the operating system level.
But for a twice-hourly job I reckon a timestamp down to minutes is probably enough.
See ?files for file manipulation functions. You can check if file exists with file.exists, and then either rename the existing file, or create a different name for the new one.

why does field value comes as 1'000,24 instead of 1,000.24 when the format is >,>>>,>>9.99 in progress 4gl?

we have recently upgraded to oe rdbms 11.3 version from 9.1d. While generating
reports,i found the field value of a field comes as 2'239,00 instead of
2,239.00.I checked the format its >,>>>,>>9.99.
what could be the reason behind this?
The admin installing the database didn't to it's homework and selected wrong default numeric and decimal separator.
However no greater harm done:
Set these startup parameters
-numsep 44 -numdec 46
This is an simplified database startup example with added parameters as above:
proserve /db/db -H dbserver -S dbservice -numsep 44 -numdec 46
When you install Progress you are prompted for the numeric format to use. That information is then written to a file called "startup.pf" which is located in the install directory (C:\Progress\OpenEdge by default on Windows...)
If you picked the wrong numeric format you can edit startup.pf with any text editor. It should look something like this:
#This is a placeholder startup.pf
#You may put any global startup parameters you desire
#in this file. They will be used by ALL Progress modules
#including the client, server, utilities, etc.
#
#The file dlc/prolang/locale.pf provides examples of
#settings for the different options that vary internationally.
#
#The directories under dlc/prolang contain examples of
#startup.pf settings appropriate to each region.
#For example, the file dlc/prolang/ger/german.pf shows
#settings that might be used in Germany.
#The file dlc/prolang/ger/geraus.pf gives example settings
#for German-speaking Austrians.
#
#Copy the file that seems appropriate for your region or language
#over this startup.pf. Edit the file to meet your needs.
#
# e.g. UNIX: cp /dlc/prolang/ger/geraus.pf /dlc/startup.pf
# e.g. DOS, WINDOWS: copy \dlc\prolang\ger\geraus.pf \dlc\startup.pf
#
# You may want to include these same settings in /dlc/ade.pf.
#
#If the directory for your region or language does not exist in
#dlc/prolang, please check that you have ordered AND installed the
#International component. The International component provides
#these directories and files.
#
-cpinternal ISO8859-1
-cpstream ISO8859-1
-cpcoll Basic
-cpcase Basic
-d mdy
-numsep 44
-numdec 46
Changes to the startup.pf file are GLOBAL -- they impact all sessions started on this machine. If you only want to change a single session then you can add the parameters to the command line (or the shortcut icons properties) or to a local .pf file or to an ini file being used by that session.
You can also programmatically override the format in your code by using the SESSION system handle:
assign
session:numeric-decimal-point = "."
session:numeric-separator = ","
.
display 123456.999.
(You might want to consider saving the current values and restoring them if this is a temporary change.)
(You can also use the shorthand session:numeric-format = "american". or "european" for the two most common cases.)

Resources