Customizing Octave - terminal

I am just starting with Octave and running it on my terminal so far.
Everytime I open the prompt, my command line starts with :
octave-3.4.0:1>
So I use the following to make it shorter and easier to read:
PS1('>> ')
How can I change my settings to exectute this code automatically everytime I open octave?
How top of this, is there a way to change my terminal settings to open Octave when I enter 'Octave'? The way I do it now is by using
'exec 'path/to/octave/
Thanks

You can create edit ~/.octaverc file that contains all the commands you want to execute when Octave starts up. This file is exactly like a .m Octave script file.
Just add PS1('>> ') to your ~/.octaverc file. You can use your favorite text editor or use echo on the command line:
$ echo "PS1('>> ')" >> ~/.octaverc
After that you can see the ~/.octaverc file :
$ more ~/.octaverc
It should contain the following line :
PS1('>> ')
For the second question, I am not sure if you're on OSX or Ubuntu or something else. If octave is in your search-path then you should be able to start Octave by just trying octave. Try these commands to find out what octave points to
$ which octave
/usr/bin/octave
$ type octave
octave is /usr/bin/octave
If somehow, octave is not your PATH search-path, this could be because you installed Octave at a non-standard location. You can do one of two things:
Add the folder containing your Octave executable to your PATH search-path. In bash, you can do this by adding the following line to your ~/.bashrc (or ~/.profile on MacOSX):
export PATH=~/path/to/octave/folder:${PATH}
You can create a soft symlink to your octave executable.
ln -s /path/to/octave/executable octave
This will create a symlink in your current folder. Now, as long as you're in the current folder, you'll be able to type in octave and run Octave. If you want to be able to run Octave from anywhere (and not necessarily the current folder), you need to add the current folder to your search-path (see point 1 above).

Consider using the latest release which is GNU Octave 3.8. It comes with a nice GUI if you're familiar with MATLAB.
You can customize the PS1 and any other settings on your ~/.octaverc. Please read the documentation on startup files: http://www.gnu.org/software/octave/doc/interpreter/Startup-Files.html
As for calling Octave from anywhere, you need to set the PATH variable in your shell to append the directory where Octave is installed, for instace in Bash:
export PATH=$PATH:/path/to/octave-3.8/bin

Start GNU Octave with option --traditional (but I'm not sure if this was already implemented in 3.4.x).
$ octave --traditional
GNU Octave, version 3.8.1
Copyright (C) 2014 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. For details, type 'warranty'.
Octave was configured for "x86_64-unknown-linux-gnu".
Additional information about Octave is available at http://www.octave.org.
Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html
Read http://www.octave.org/bugs.html to learn how to submit bug reports.
For information about changes from previous versions, type 'news'.
>> version
ans = 3.8.1
>>

Related

Fixing <right arrow> in bash vi input mode. Cannot type beyond last character

I'm trying to use vi mode in bash. via the .inputrc (on OSX):
set editing-mode vi
In vi insert mode, the right arrow key moves the cursor to the right, but it stops on the last character in the line. If the cursor is past the end of the line, it moves the cursor to the left. So, in sum, the farthest right you can go is to the last character in the line.
$ cd /usr/locl/bin
# Move the cursor to the middle of the line, and fix something there
$ cd /usr/local/bin
# Now move the cursor back to the end, and write a character (/)
$ cd /usr/local/bi/n
As shown above this means you cannot edit the end of the line without going into command mode (and using 'a').
I found an article which seems to indicate the version of readline/bash might be the problem. However I used brew to upgrade bash (GNU bash, version 4.3.42), and even tried to install and link readline (6.3.8), as recommend by that site. But no luck. Its possible the upgrade was done incorrectly.
This means I'm looking for one of the following:
The proper way to upgrade bash and readline in OSX terminal
A way to check the versions of bash/readline that OSX is actually using
Another fix for this bug (somehow passing in the virtualedit=onemore option in the inputrc)
Indications that the latest versions of readline might have re-introduced the bug, and solutions.
Also: if theres a similar thing with editrc
Note: I'm looking to make readline in bash act near identical to the default (for others who periodically use my terminal), but allow me to use vim mode. This means I don't need workarounds, but fixes.
Answer here: https://unix.stackexchange.com/a/222506/198846
Apparently it's a bug in the bash version shipped with OSX (3.2), it's fixed in 4.3 according to that answer. Use bash --version to check your bash version.
To fix, update bash, e.g.
macports: sudo port install bash
brew: brew install bash
Once installed bash --version will show it's updated (assuming standard brew/macports paths at the start of your $PATH)
You then have to change your default login shell (in System Preferences->Users & Groups->right click your user->advanced options->login shell) to the path of the new bash:
(default) macports: /opt/local/bin/bash
(default) brew: /usr/local/bin/bash
Changing the default login shell step is required even if which bash shows the macports/brew one.
All credit to the answer linked above.
Can't you edit .bashrc itself instead to use vi mode? The command set -o vi does it in my case (you are in edit mode initially). Also remove the .inputrc edit as the two may actually interact nefariously afterwards.

How to use default path for ActivePerl 5.20 Mac OS X (/usr/bin/perl) instead of /usr/local/ActivePerl...?

I have installed ActivePerl 5.20.2 today on Mac OS X 10.9.5
Checking the version of perl in Terminal (perl -v) I see 5.20.2
So everything seems to be ok. But..
When I start my CGI scripts the script is running under built in perl (which is 5.16) (if using #!/usr/bin/perl).
If I use #!/usr/local/ActivePerl5.20.2/bin/perl then it runs under 5.20.2 that is required.
The question is: is it somehow possible to change the directory for using in my scripts from #!/usr/local/ActivePerl5.20.2/bin/perl to simple and familiar #!/usr/bin/perl keeping running under ActivePerl instead of built in.
I need to override the system's default version with the new ActivePerl.
I would be appreciated for your detailed answers (with name of files and directories where they are located) if ones are to be changed to implement salvation.
Thanks!
The question is: is it somehow possible to change the directory for using in my scripts from #!/usr/local/ActivePerl5.20.2/bin/perl to simple and familiar #!/usr/bin/perl keeping running under ActivePerl instead of built in.
Don't even try. That way lies damnation, not salvation. The ability to specify the specific interpreter that will handle your scripts is an important feature.
Instead, package your CGI script as a simple CPAN module. Then, install it using the familiar
$ /usr/local/ActivePerl5.20.2/bin/perl Makefile.PL
$ make install
routine. The shebang line will be automatically adjusted to reflect the perl that was used to build and install your package.
First, instead of specifying a particular path to your Perl interpreter in your script:
#! /usr/local/ActivePerl5.20.2/bin/perl
or
#! /usr/bin/perl
Specify this:
#! /usr/bin/env perl
This will find the first executable Perl interpreter in your $PATH and then use that to execute your Perl script. This way, instead of having to change your program, you only have to change the $PATH variable.
Next time, take a look at PerlBrew for installing a different version of Perl. PerlBrew will allow you to install multiple versions of Perl all under user control, and let you select which version of Perl you'd like to use.
I also recommend to put /usr/local/bin as the first entry in your $PATH. Then, link the executables you want to run to that directory. You can use something like this to create your links:
for file in $/usr/local/ActivePerl5.20.2/bin/*
do
basename=$(basename $file)
ln -s "$file" "/usr/local/bin/$basename"
done
This way, all programs you want to execute are in the same directory which makes setting $PATH so much easier. I even put /usr/local/bin in before /usr/bin and /bin because I want to be able to override the system's default version.

How to have Matlab recognize my $PATH?

I am using the GraphViz interface for Matlab (link), and noticed that Matlab's calls to the shell (e.g., via system or !) return with errors (command not found) when attempting to call graphviz or neato or other related names, which are perfectly valid when called from my own default shell (bash, using Terminal on OSX).
Well, I installed graphviz to my system using homebrew, so it should work fine -- I tested !brew -v from Matlab and it doesn't work either! So, I checked my path. In bash, echo $PATH returns
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin
while in Matlab, !echo $PATH returns /usr/bin:/bin:/usr/sbin:/sbin
So, this is potentially causing my problems. That said,
1) How can I have Matlab either automatically sync the correct path, or do so once-per-startup? (i.e., so I could put the code into startup.m)
2) Can someone diagnose what causes Matlab to not find the correct environment variables, and whether this is a global problem or likely specific to my configuration?
Many thanks!
The most likely explanation for what you are seeing is that Matlab is being run on your OSX distribution under a different user than your own profile.
When you do an echo $PATH from Matlab, it is showing you the PATH for the user under which Matlab is running. However, when you do echo $PATH from the command line, it is showing you the PATH for your user profile.
To correct this, please investigate the way you are running Matlab, and make sure you are running it as yourself (or as a user who has the correct PATH settings).
Update:
I downloaded Matlab 8.5 on my Fedora box at home. I was unable to run it unless I did so using sudo su followed by ./matlab. What I observed is that Matlab caches the value of the PATH variable of the Linux user who launched it for the entire session. Changing the PATH during a Matlab session did not change the output of !echo $PATH in Matlab.
Please try to reproduce the following on your setup:
Type sudo su from a Terminal window
echo $PATH and record what you see
./matlab Start Matlab
!echo $PATH from within Matlab. What you see should match Step 2.
Kill Matlab, and do export PATH=$PATH:/newpath/ from the same Terminal
Repeat steps 3 and 4, and you should see the new PATH value in Matlab

pandoc version 1.12.3 or higher is required and was not found (R shiny)

I have a problem generating a pdf report from my app shiny which is hosted on a server.
the app works fine but when I press the button to download the report, I get this error :
pandoc version 1.12.3 or higher is required and was not found.
The proble is that if I type pandoc -v I get:
pandoc 1.12.3.3
Compiled with texmath 0.6.6, highlighting-kate 0.5.6.1.
Syntax highlighting is supported for the following languages:
actionscript, ada, apache, asn1, asp, awk, bash, bibtex, boo, c, changelog,
clojure, cmake, coffee, coldfusion, commonlisp, cpp, cs, css, curry, d,
diff, djangotemplate, doxygen, doxygenlua, dtd, eiffel, email, erlang,
fortran, fsharp, gnuassembler, go, haskell, haxe, html, ini, java, javadoc,
javascript, json, jsp, julia, latex, lex, literatecurry, literatehaskell,
lua, makefile, mandoc, markdown, matlab, maxima, metafont, mips, modelines,
modula2, modula3, monobasic, nasm, noweb, objectivec, objectivecpp, ocaml,
octave, pascal, perl, php, pike, postscript, prolog, python, r,
relaxngcompact, restructuredtext, rhtml, roff, ruby, rust, scala, scheme,
sci, sed, sgml, sql, sqlmysql, sqlpostgresql, tcl, texinfo, verilog, vhdl,
xml, xorg, xslt, xul, yacc, yaml
Default user data directory: /home/daniele/.pandoc
Copyright (C) 2006-2013 John MacFarlane
Web: http://johnmacfarlane.net/pandoc
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.
So I suppose I have the right version for that. TexLive is also installed and the path is in $PATH.
Server.R
library(shiny)
library(drsmooth)
library(shinyBS)
library(knitr)
library(xtable)
library(rmarkdown)
shinyServer(function(input, output,session) {
output$downloadReport <- downloadHandler(
filename = function() {
paste('report', sep = '.','pdf')
},
content = function(file) {
src <- normalizePath('report.Rmd')
# temporarily switch to the temp dir, in case you do not have write
# permission to the current working directory
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(src, 'report.Rmd')
library(rmarkdown)
out <- render('report.Rmd')
file.rename(out, file)
})
output$tb <- renderUI({
p(h4("Report")),
"Dowload a the report of your analysis in a pdf format",
tags$br(),downloadButton('downloadReport',label="Download report"),
tags$em("This option will be available soon")
})
})
* report.Rmd* does not contain any sort of calculation, it's only text.
The pdf generation works fine on my local version (MacOS) but not on the server.
I'm here to give other information if needed.
Go into RStudio and find the system environment variable for RSTUDIO_PANDOC
Sys.getenv("RSTUDIO_PANDOC")
Then put that in your R script prior to calling the render command.
Sys.setenv(RSTUDIO_PANDOC="--- insert directory here ---")
This worked for me after I'd been struggling to find how rmarkdown finds pandoc. I had to check github to look at the source.
Another option so that this works for all your R scripts is to define this variable globally.
On Debian/Ubuntu, add the following line to your .bashrc file:
export RSTUDIO_PANDOC=/usr/lib/rstudio/bin/pandoc
On macOS, add the following to your .bash_profile file:
export RSTUDIO_PANDOC=/Applications/RStudio.app/Contents/MacOS/pandoc
On Windows (using Git Bash), add the following to your .bashrc file:
export RSTUDIO_PANDOC="/c/Program Files/RStudio/bin/pandoc/"
The easiest way I solved this issue is to pass the Sys.setenv(..) command inside the crontab command prior to calling the RMarkdown::render. You need to separate the two commands with a semicolon:
R -e "Sys.setenv(RSTUDIO_PANDOC='/usr/lib/rstudio-server/bin/pandoc'); rmarkdown::render('File.Rmd', output_file='output.html')"
(Remember that the rstudio-server path differs from the non-server version)
For those not using RStudio, you may just need to install pandoc on your system. For me it was
sudo pacman -S pandoc
and it worked (Arch Linux).
I'm using Arch Linux, and RStudio as well..
the only thing that worked for me was:
sudo pacman -S pandoc
:)
If anyone is having this issue and also use anaconda, its possible they were having my issue. The rstudio shell does not load the .bashrc file when it starts up meaning if your version of pandoc is installed within anaconda Rstudio will not find it. Installing pandoc separately with a command like sudo pacman -S pandoc worked for me!
I had a similar problem with pandoc on Debian 10 while building a bookdown document. In the Makefile what I did was:
# use rstudio pandoc
# this rule sets the PANDOC environment variable from the shell
build_book1:
export RSTUDIO_PANDOC="/usr/lib/rstudio/bin/pandoc";\
Rscript -e 'bookdown::render_book("index.Rmd", "bookdown::gitbook")'
# use rstudio pandoc
# this rule sets the environment variable from R using multilines
build_book2:
Rscript -e "\
Sys.setenv(RSTUDIO_PANDOC='/usr/lib/rstudio/bin/pandoc');\
bookdown::render_book('index.Rmd', 'bookdown::gitbook')"
These two rules are equivalent and knit the book successfully.
I just didn't like the long Rscript command:
Rscript -e "Sys.setenv(RSTUDIO_PANDOC='/usr/lib/rstudio/bin/pandoc'); bookdown::render_book('index.Rmd', 'bookdown::gitbook')"
Hey I just beat this error. I solved this by deleting the 2 pandoc files, "pandoc" and "pandoc-citeproc" from the shiny-server folder. I then created a link for each of these files from the rstudio-server folder. It worked like a charm. This was an issue for me when I was trying to embed leaflet in the rmarkdown documents from running a shiny-server on a linux machine. I found it odd that when I ran it in rstudio on the same linux machine it worked fine, but not when I ran it using shiny-server. So the shiny-server install of pandoc is old/outdated.
Cheers
For Windows 10, RStudio 2022.12.0
Pandoc is installed with RStudio, so I prefer to use the already-installed pandoc.exe. As far as I can tell where it is installed changes from time to time. In the last couple of years, I've seen it in the below locations (the top one is where it is with my current verison of RStudio).
January 2023-
"C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools"
August 2022-
"C:/Program Files/RStudio/bin/quarto/bin/tools"
"C:/Program Files/RStudio/bin/quarto/bin"
"C:/Program Files/RStudio/bin/pandoc"
Once you know where the pre-installed pandoc is you can include this line in your .R file as the top answer from Chris/Yihui indicate and it works for me.
Sys.setenv(RSTUDIO_PANDOC = "C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools")
If you are trying to run a script from the command line on Windows you just need to have the directory path in the PATH variable*. You can also create a separate User variable named RSTUDIO_PANDOC and give this variable the directory*. Then close and reopen any terminals to refresh the system paths.**
*Experiment with a trailing / if you are having issues.
**I was unable to point to a UNC path. The // at the beginning of the path hosed the rmarkdown package pandoc functions. If you are using a UNC path, you must map it to a drive and reference the drive letter. There are ways to do this dynamically. I use a DOS/batch script which I found via Google.
I was facing a similar issue in IntelliJ R plugin. I solved it by copying the pandoc file in ~/.IntelliJIdea2019.3/config/plugins/rplugin/pandoc
On Windows, and without RStudio, you can install pandoc with choco install pandoc or via the pandoc website, https://pandoc.org/.
Make sure to restart your IDE to ensure it picks up the new install.

Cant call PDFtk from Matlab, but can from terminal

For some reason, when I try to call PDFtk from Matlab (pdftk *.pdf cat output combFile.pdf), I get a /bin/bash: pdftk: command not found error, but I can run the same command in terminal in the same directory with no problem. I have restarted my system, but that did not seem to help. I am running Mac OSX 10.9.1 and Matlab 2013b. I do not want to use the absolute path to PDFtk, because it needs to be cross-platform compatible.
EDIT: This may help. When I echo $PATH in Matlab I get /usr/bin:/bin:/usr/sbin:/sbin. When I do it in terminal, I get /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin. Then I did which pdftkand it returned /usr/local/bin/pdftk Is there anyway to add the /usr/local/bin/ path to Matlab?
I believe that the export PATH idea would probably be better for a single system (note: I have not tested it), but I needed my script to be used on several Mac and Linux machines that are out of my control. This is what I ended up using (yes, I know that this will break on Windows, but that is ok)
if(ismac)
system('/usr/local/bin/pdftk myfig[0-9][0-9].pdf cat output myfigCombined.pdf');
else
system('/usr/bin/pdftk myfig[0-9][0-9].pdf cat output myfigCombined.pdf');
end
Originally, I was using if(isunix) for the second command, but presumably because of Mac's unix architecture both commands were being executed.
EDIT: I was able to test it on Linux and it worked perfectly. I suppose this would be the syntax for Windows, but I do not have access to a Windows machine with PDFtk and Matlab installed, so no guarantees (also, I am not sure that I did the path quotation marks right...):
elseif (ispc)
system('"C:\Program Files (x86)\PDFtk Server\bin\pdftk" myfig[0-9][0-9].pdf cat output myfigCombined.pdf');
It seems that your $PATH environment variable is not exported to Matlab. Reading
http://www.mathworks.com/matlabcentral/newsreader/view_thread/255609
I'd suggest to add a
export PATH=$PATH:<Path-to-your-PDFtk-binary>
in your .bash_profile

Resources