R animation error: how to install ImageMagick? - r

I intend to run some R Animation demo code but this error message returns
Warning messages:
1: In im.convert(img.files, output = movie.name, convert = convert, :
Please install ImageMagick first or put its bin path into the system PATH variable
I've downloaded ImageMagic for mac. It's a folder with subfolders like bin, lib, share etc. How can put its bin path into system path? Thanks.

Option 1:
Put something like
PATH=$PATH:blablabla/ImageMagic/bin
in ~/.bashrc file.
$PATH is the original PATH variable;
: is used to separate different candidates;
the final blablabla/ImageMagic/bin denotes the path to the executable.
Whenever you open up a new terminal, ~/.bashrc file will be run, hence environmental variable PATH will be set as above. If you start up your R from terminal, this should do the work.
Option 2:
If you normally invoke R by clicking its icon, then ~/.bashrc may not work. In this case, use the ~/.profile file instead. This is run whenever you log in. Add the following to the bottom of this file:
export PATH=$PATH:blablabla/ImageMagic/bin
(Note export here. You may need to log out and log in again so that the setting takes effect.)
Comments
Both ~/.bashrc and ~/.profile are hidden files. You may use ls -a ~ to see them. To edit/save them, use the normal text editor.
The link #Gregor gives, suggests using ~/.bash_profile. Well, These days this file is normally replaced by ~/.profile. But you should use ls -a ~ to check.
follow up:
OK, so you have .bash_profile instead of .profile on your machine.
To open this file, do:
sudo nano ~/.bash_profile
Then move to the bottom, and add the line you need:
export PATH=$PATH:blablabla/ImageMagic/bin
To save edit, do ctrl + O (maybe hitting an ENTER as well); then you quit editor by ctrl + X.
If you do not want to log out and log in again to let new setting take effect, try:
source ~/.bash_profile

I had the same problem with Windows a few weeks ago. I don't know if it is the same on Mac or not, but it is worth a try.
When you go to download ImageMagick there should be a prompt that says something like "select additional tasks." Be sure to check "Install Legacy Utilities (e.g. convert)." I think they changed the names of a few things between versions. That selection names things properly for R. Also, if this happens to be the same issue I had (maybe, maybe not) be sure to restart R before trying again after you've downloaded it.

Related

How to run Python, R, Octave or Julia using BowPad?

I try using a very light-weighted editor BowPad to edit and run codes.
Take running R as an example, which has been added to Windows PATH Environment Variable D:\R\R-3.6.2\bin\x64
I try to take some following steps:
I built a test.r writing some testing line codes as 1+2; plot(1:10)
Menu --> Run --> Configure custom commands
Command Name: run R
Command Line: D:\R\R-3.6.2\bin\R.exe $(SEL_TEXT)
$(LINE) The line where the cursor is
$(POS) the position where the cursor is
$(TAB_PATH) the path to the file of the active tab
$(TAB_NAME) the file name without extension of the current tab
$(TAB_EXT) the file extension of the current tab
$(TAB_DIR) the directory of the file of the active tab
$(SEL_TEXT) the selected text or the word at the cursor position
$(SEL_TEXT_ESCAPED) like $(SEL_TEXT) but escaped, useful for urls
When I press to choose run R to run the code, something wrong happens!
It will open a Rterm(64-bit) window each time when I run R!
it shows RGUMENT '1+2' __ignored__ or ARGUMENT 'plot(1:10)' __ignored__
Did I missing something ? BTW, can we set some shortcuts keys for running Python, R, Octave or Julia?
Also, when I reach the homepage of BowPad for more information, little usage of this software can be found!
R.exe refers to Rterm. You can use Rgui.exe instead but that won't automatically process arguments. I think what you likely want is to send the selected text to a running R session rather than starting up a new R session each time.
To do that
download this file and optionally place it on your path https://raw.githubusercontent.com/ggrothendieck/batchfiles/master/clip2r.js
in the Bowpad Run | Configure window configure a Run R command as the following (or if clip2r.js is not on your path use the entire pathname). It should be just like this with no arguments.
clip2r.js
From the Windows cmd line if Rgui is running we see that tasklist | findstr Rgui finds Rgui as the R gui process and you can create additional js scripts by editing clip2r.js replacing Rgui in the js script with whatever is the appropriate word to locate python, julia, octave or other R front end assuming again that they are running.
Now to invoke it from within Bowpad:
ensure that your Rgui session is already running and
from within Bowpad select the code you want to run and copy it to the clipboard and then invoke Run R. For example, to run everything use ctrl A ctrl C ctrl R 0 assuming that Run R is in position 0 in the configure menu. Alternately use the mouse with the Ribbon.
Regarding the comment about difficulty finding help, it looks like Bowpad is based on Scintilla so the documentation for it and the related SciTE editor likely apply to Bowpad too. You can also check the Bowpad source code on github.

RVM showing Ruby version in ZSH

I just installed rvm to upgrade ruby using the method outlined here. After installation my zsh instance now always displays rvm:ruby-2.3.0, as per this image:
I'd rather it not appear but I'm having trouble finding where it's set, any thoughts? It's pretty annoying.
Thanks!
If, like me, you ended up here because of this problem with the powerlevel10k theme, do the following:
Open ~/.p10k.zsh
Find the line:
rvm # ruby version from rvm (https://rvm.io)
Comment it out:
# rvm # ruby version from rvm (https://rvm.io)
Open a new terminal
Your prompt is set in a .zsh-theme file that is specified in your
.zshrc file in your home directory.
Changing to another theme:
If you want to change your prompt to a preexisting one, open your .zshrc file with your favorite text editor. Your can find your .zshrc in ~/.zshrc. When you open that file you will see a line that looks something like this: ZSH_THEME="gallois". (It looks like you're using gallois)
This is the line that you should change if you want to change your entire prompt. For example, change your this from ZSH_THEME="gallois" to ZSH_THEME="dallas" to change to the preexisting dallas theme. Click here For a list of all the default themes and what they look like. These themes are located in ~/.oh-my-zsh/themes.
You should then run . ~/.zshrc to source zsh and you will see the new prompt.
Editing the gallois theme to remove the right prompt
These themes are located in ~/.oh-my-zsh/themes. I would recommend copying the gallois.zsh-theme file and making some other file like yourname.zsh-theme. In the theme file you can remove the right prompt entirely by removing the line below this comment:
# Combine it all into a final right-side prompt
RPS1='$(git_custom_status)$(ruby_prompt_info) $EPS1'
You should probably remove this from the theme file as well for good measure:
# RVM component of prompt
ZSH_THEME_RVM_PROMPT_PREFIX="%{$fg[red]%}["
ZSH_THEME_RVM_PROMPT_SUFFIX="]%{$reset_color%}"
#Customized git status, oh-my-zsh currently does not allow render dirty status before branch
git_custom_status() {
local cb=$(git_current_branch)
if [ -n "$cb" ]; then
echo "$(parse_git_dirty)%{$fg_bold[yellow]%}$(work_in_progress)%{$reset_color%}$ZSH_THEME_GIT_PROMPT_PREFIX$(git_current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
}
Keep in mind, this will also remove any descriptions about git repos from your prompt. You should then run . ~/.zshrc to source zsh and you will see the new prompt.
Editing the gallois theme to only remove the ruby prompt
These themes are located in ~/.oh-my-zsh/themes. I would recommend copying the gallois.zsh-theme file and making some other file like yourname.zsh-theme. In the theme file you can remove just the rvm prompt by removing a portion of this line:
# Combine it all into a final right-side prompt
RPS1='$(git_custom_status)$(ruby_prompt_info) $EPS1'
If you just remove the $(ruby_prompt_info) portion so that it looks like this:
# Combine it all into a final right-side prompt
RPS1='$(git_custom_status) $EPS1'
Then you can skip to the end and only remove the rvm portion of the prompt. I would also recommend removing these lines to avoid cluttering the theme file:
# RVM component of prompt
ZSH_THEME_RVM_PROMPT_PREFIX="%{$fg[red]%}["
ZSH_THEME_RVM_PROMPT_SUFFIX="]%{$reset_color%}"
You should then run . ~/.zshrc to source zsh and you will see the new prompt.
Another way to hide the ruby version information is to override the ruby_prompt_info() function used to determine what gets included in the prompt.
To do this, edit your ~/.zshrc and add the following after $HOME/.rvm/scripts/rvm has been sourced:
# hide ruby version from ps1
function ruby_prompt_info() { echo '' }

What is the equivalent to R_HISTFILE for R data files

.RData files are starting to invade my directory structure. I would like to retain a single one in a specified directory. Is there such an ENV variable similar to R_HISTFILE?
This is in reference to the default save/restore directory for R workspaces.
UPDATE The answer by JThorpe led to the following solution:
set Env var RPROFILE_USER to a desired location . I am using my home dir
i.e.:
export RPROFILE_USER=/Users/steve
In that directory create a file with setwd (set working directory)
i.e:
$cat ~/.Rprofile
setwd('/Users/steve')
Now the .RData will always load/save to the home dir (or whatever dir you put in setwd)
I personally dislike having R retain anything between sessions b/c it makes for difficult to find errors owing to variables that persist between sessions. Hence I set the “no-save” and “no-restore” options so that R neither writes its current state to an .Rdata file nor attempts to read in an old state. If I do happen to want to save an R session (this happens VERY rarely) I call savehistory().
Methods for setting command line options in OSX can be found here, and what follows describes setting command line options for R (or any other program) in windows.
To set the no-save and no-restore options in Windows, right-click on the R icon that you use to start an R session and select the ‘properties’ option. In the properties box, the “target” string should look something like this:
“C:\Program Files\R\R-3.1.2\bin\i386\Rgui.exe”
To this string, add this string ‘ --no-save --no-restore’. Note that there is a space before each of the double-dashes. The target should now look something like this:
“C:\Program Files\R\R-3.1.2\bin\i386\Rgui.exe” --no-save --no-restore
Click ‘Ok’ or ‘Apply’ to save these options. Note that these are per-icon (shortcut) settings. I have several icons with different command line options depending on the setting I want in the R session. Additional command line arguments to R can be found here.
Try the Load command in the Hmisc package. It uses the LoadPath option for this.
If you create a .Rprofile file you can specify a default working directory. See ?Startup for more details including the ability to set a site-wide profile. I just referred to that help page to make sure the .RData would be affected by that setting.

How do I make R run R Commander every time it starts up?

I used to have it set up that R commander plug-in would start up automatically every time I opened the R application, but I've upgraded R and can't remember how I did it.
Here is Scott Hyde's instructions for creating a shortcut to start R commander every time you start R.
Open up the C:\Program Files\R\R-2.10.1\etc (or similarly named version directory).
Edit the file Rprofile.site and add the following lines. The mylibs variable is a list of packages that you want starting up each time you run Rcmdr. Both lattice and MASS are depencies of Rcmdr and need to be loaded. If you load them this way, they are loaded SILENTLY!
defpack = getOption("defaultPackages")
mylibs = c("tcltk","car","lattice","MASS","Matrix")
if(Sys.getenv("RCMDR") == "TRUE") mylibs = c(mylibs,"Rcmdr")
options(defaultPackages = c(defpack,mylibs))
Next, copy the shortcut that is used to run R onto the Desktop. Right click on the file, and select properties Add the following to the end of the "Target:"
"C:\Program Files\R\R-2.10.1\bin\Rgui.exe" --sdi RCMDR=TRUE
Notice that the options are OUTSIDE of the quotation marks.
Change the name of the shortcut you just made to "Rcmdr"
Double click on it, and both R and Rcmdr start!
Recently started using R, and I was testing out the other solution given by #user123943, and it just couldn't seem to work out right. Thought maybe there'd be a simpler solution and tried it and it worked fine. All you need to do is:
Find the Rprofile.site file (it should be in an etc file somewhere inside your R program file) (e.g.: C:\Program Files\R\R-4.1.1\etc)
Edit the file (give yourself permissions to edit if required) by adding in library(Rcmdr) at the end of the file.
That's it! Quick and easy solution! If you decide to revert it back all you will need to do is remove the added code at the end of the Rprofile.site file :)
Of course, save the file before opening up R again!

How can I load my .RProfile using Textmate's R Bundle

This question is for those of you who happen to use R, on a Mac, in combination with Macromate's [Textmate](http://macromates.com/) text editor and the "R" Bundle. All of which are nifty, needless to say, but that's beside the point for now :-)
I've got a .RProfile file sitting in my default "~" startup directory, and it's got a number of useful functions in it I like to have access to when writing R scripts. But I also use Textmate for most of my writing, and the cmd-R functionality to to run my scripts within Textmate.
At the moment, I don't know how to tell Textmate where my .Rprofile is.
Is there a way--most likely through Textmate's Bundle settings--that I can point Textmate to my .RProfile so I don't have to write my functions into every script on a per-script basis?
OR
Is it actually better to include any custom functions in any script I write, so that anyone with a basic R setup can source and run my scripts?
I feel like I must be missing a dead-easy setting or config file here within either Textmate or the R environment it calls to run my scripts.
Thanks so much in advance!
The R Bundle Developer is apparently working on this (see this Post on the Mailing List) but it's not available at the moment.
In the meantime, you have a couple of choices.
First, you can create a new bundle (e..g, "briandk-R") then create a snippet w/in that bundle either with 'source($1)' or just hardcode the file you want to source instead of the placeholder (so, e.g., "source("~/some_file_to_source.R"). If you do the latter, then you can configure TM to source your file via a tab trigger (in the Bundle Editor, toggle over to 'settings' (upper left hand corner) and type "source.r, source.rd.console" in the 'Scope Selector' field then choose a few letters for your tab trigger (e.g., "src.")
If you don't want to do that, go to the 'Rdaemon' Directory (which is either in your home directory or in ~/Library/Application Support/Rdaemon). Look in this directory and you will see another directory called "daemon.' In there is a file called "start.r" which lists the files that are sourced upon starting R from the Rdaemon. You know what to do from there. (Note: This directory also contains a couple of other scripts which contain initial settings; you might wish to have a look at those as well)
The first part of Doug's response offers the simplest immediate solution... add
source('/Users/briandk/.Rprofile')
to the head of any .r files you want those functions in... with that one line of code, you get your utility functions. Of course, that only helps if you're running the whole TM file.
Ideally, the bundle will be updated... perhaps to support a shell variable via TM's preferences???
TM_RPROFILE
which could be set to the path to your .Rprofile file.
I just hacked this into tmR.rb with just 2 lines of code. To implement this, go to ~/Library/Application Support/TextMate/Pristine Copy/Bundles/ and Show the Contents of R.tmbundle
In there, you'll find support/tmR.rb
in my version, near line 112, you should change
tmpDir = File.join(ENV['TMP'] || "/tmp", "TM_R")
recursive_delete(tmpDir) if File.exists?(tmpDir) # remove the temp dir if it's already there
Dir::mkdir(tmpDir)
# Mechanism for dynamic reading
# stdin, stdout, stderr = popen3("R", "--vanilla", "--no-readline", "--slave", "--encoding=UTF-8")
stdin, stdout, stderr, pid = my_popen3("R --vanilla --slave --encoding=UTF-8 2>&1")
# init the R slave
stdin.puts(%{options(device="pdf")})
stdin.puts(%{options(repos="#{cran}")})
to
tmpDir = File.join(ENV['TMP'] || "/tmp", "TM_R")
recursive_delete(tmpDir) if File.exists?(tmpDir) # remove the temp dir if it's already there
Dir::mkdir(tmpDir)
rprofile = (ENV['TM_RPROFILE'] == nil) ? "" : "source('" + ENV['TM_RPROFILE'] + "')"
# Mechanism for dynamic reading
# stdin, stdout, stderr = popen3("R", "--vanilla", "--no-readline", "--slave", "--encoding=UTF-8")
stdin, stdout, stderr, pid = my_popen3("R --vanilla --slave --encoding=UTF-8 2>&1")
# init the R slave
stdin.puts("#{rprofile}")
stdin.puts(%{options(device="pdf")})
stdin.puts(%{options(repos="#{cran}")})
Just added 2 lines there... the one that begins "rprofile =" and the one that includes "#{rprofile}"
-Wil

Resources