open file with shell() in R - windows

I want to open a file in a windows program using R, but specifying the program rather than the default for the file extension, and for a file not necesarrily in my current R session home directory (this one getwd())
From looking at the documentation, using shell(), should be the way, but I seem to have an issue with the way R references the home directory or the way I'm writing the string.
e.g.
This works ok in the cmd "run" in windows: excel e:\test.xlsx
but using this
route <- "e:\\test.xlsx"
shell(paste("excel " , route, sep=""), flag="")
seems to get to excel (excel copyright notice is printed), but also prints the home directory and doesn't open the file in route. Thanks for any help.

Your command does the same for me. However, this works:
shell(paste("start", "excel", route))

Related

How to set Crtrl+r to execute commands in Rstudio

How can I set RStudio to use Ctrl+R (in addition to Ctrl+Enter) to execute commands?
https://community.rstudio.com/t/bring-ctrl-r-back/1846 suggests editing the "rstudio_bindings.json" file, but I can't find the file.
https://support.rstudio.com/hc/en-us/articles/206382178-Customizing-Keyboard-Shortcuts gives instructions to add using from the menu options. I tried to add "Ctrl+Enter|Ctrl+R" as suggested in the first link but this is not accepted. At the bottom of the page it describes how the bindings are saved at ~/.R/rstudio/keybindings/rstudio_commands.json or ~/.R/rstudio/keybindings/editor_commands.json. I cannot find either of these files.
How can I do this?
R version 3.4.2
RStudio Version 1.1.383
Windows 7
Following advice from https://community.rstudio.com/t/bring-ctrl-r-back/1846,
you have to edit the file ~/.R/rstudio/keybindings/rstudio_bindings.json with
{
"executeCode" : "Ctrl+Enter|Ctrl+R"
}
These directories and file already existed on Ubuntu, however, neither the file nor any of the directories existed on my Windows partition. So needed to create the nested directories .R/rstudio/keybindings, and then create the json file shown above, and save it as rstudio_bindings.json.
(aside: Windows didn't like trying to name a new folder of .R (the leading dot gave problems), but you can get round this by naming .R. , as the trailing dot is removed from here )

Processing 3.0 launch() function doesn't launch my .exe

Processing 3.0 launch function doesn't launch my .exe.
I am using the Launch() function (https://processing.org/reference/launch_.html)
launch("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe");
Or
launch("C:/app/keyboard.exe");
Result: Chrome browser will open. keyboard.exe will not. I've tryed different locations and relative paths.
I only get a windows loader when the link is correct. So that is correct.
The function discriptions says this:
"Be sure to make the file executable before attempting to open it (chmod +x). "
https://superuser.com/questions/106181/equivalent-of-chmod-to-change-file-permissions-in-windows
I also made a .bat file to execute the .exe but the launch() function only works on exe files.
but that didnt work either.
System:
Processing 3.0
Java 8
Windows 10, 64 bit
So what am I missing?
It is a bit dodgy but works in windows 8:
PrintWriter output=null;
output = createWriter("myfile.bat");
output.println("cd "+sketchPath(""));
output.println("start archivo.exe");
output.flush();
output.close();
output=null;
launch(sketchPath("")+"myfile.bat");
And you can choose another relative or absolute path
for instance
output.println("cd ..");
output.println("cd directoriy");
...
As Samuil advises, Windows uses \ instead of a / as a separator character, which you'll need to escape, hence \\: launch("C:\\app\\keyboard.exe");
I recommend using File.separator:
launch("C:"+File.separator+"app"+File.separator+"keyboard.exe");
It's a bit longer, but will work regardless of the operating system(Linux/OSX/Windows/etc.).
Aside launch(), also try exec():
exec(new String[]{"start","C:"+File.separator+"app"+File.separator+"keyboard.exe");
also Process. (If you need to check the output, you may need to write your own thread that will pipe the output)

How to (easily) get current file path in Sublime Text 3

How to (easily) get current file path in Sublime Text 3
I don't often use ST console (I used it only once to install package manager), but I suppose it could be good way to :
get current file path like some kind pwd command.
But it doesn't work.
Does anyone know an easy way to get current file path?
to clipboard : better not a strict objective in the answer
not necessary by ST command, maybe package?
Right click somewhere in the file (not on the title tab) --> Copy file path
If you don't want to use the mouse, you could set up a keyboard shortcut as explained here https://superuser.com/questions/636057/how-to-set-shortcut-for-copy-file-path-in-sublime-text-3
To easily copy the current file path, add the following to Key Bindings - User:
{ "keys": ["ctrl+alt+c"], "command": "copy_path" },
Source
Key Bindings - User can be opened via the command palette (command + p on OSX)
Easy to understand using image. On Right Click you will get this.
Transcribed code in image for convenience:
import sublime, sublime_plugin, os
class CopyFilenameCommand(sublime_plugin.TextCommand):
def run(self, edit):
if len(self.view.file_name()) > 0:
filename = os.path.split(self.view.file_name())[1]
sublime.set_clipboard(filename)
sublime.status_message("Copied file name: %s" % filename)
def is_enabled(self):
return self.view.file_name()... # can't see
Mac OS X - Sublime Text 3
Right click > Copy File Path
A lot of these answers involve touching the mouse. Here's how to do get the path without any mouse clicks using SideBarEnhancements
Install SideBarEnhancements using PackageControl.
Click super + shift + P to open the command palette
In the command palette begin typing path until you see File: Copy Path
Select File: Copy Path
Now the path to file you are working in is copied into your clipboard.
There is a Sublime Package which gives your current file location inside a status bar. I just cloned them directly to my /sublime-text-3/Packages folder.
git clone git#github.com:shagabutdinov/sublime-shell-status.git ShellStatus;
git clone git#github.com:shagabutdinov/sublime-status-message.git StatusMessage;
You have to check/read the description on GitHub. Even it is listed in package control it would not install properly for me. You can actually edit the shell output as you want. If you have the right skills with python/shell.
Looks like this (Material Theme)
If you're like me and always click on items in the sidebar just to realize that copying the path only works when clicking in the editor area, have a look at the SideBarEnhancements package. It has a huge bunch of options to copy file paths in a variety of different ways.
Installation is available via Package Control (despite the webpage only mentions installation via manual download).
Note: The package “sends basic, anonymous statistics”. The webpage explains how to opt out from that.
Go to this link. The code in the link is given by robertcollier4.
Create a file named CpoyFileName.py or whatever you like with .py extension.
Save the file in Sublime Text 3\Packages\User folder. Then paste the above given key bindings in your Preferences: Key Bindings file.
Now, you can use the specified key bindings to copy just filename or total (absolute) filepath.
Please note that the filename or filepath do contain file extension.
Fastest Solution ( No Packages Needed + Comprehensive ):
Folder Path:
Folder in "Sidebar"
Right Click
"Find In Folder"
"Where" field contains everything you need
File Path:
File in current "Tab"
Right Click
"Copy File Path"

How to remove part of a string in a Windows Bat file and prepend another part of a string to it?

I am trying to add a Windows Context Menu item that will let me right click a file in Windows Explorer and click a button Open in Dev Server.
This will then pass the file path of the selected file to a Windows .bat file.
In my .bat file openLocalHostWebBrowser.bat so far I have this code below which wehn ran opens a new tab in my web browser with the supplied URL.
#echo off
start "webpage name" "http://someurl.com/"
So I need help. I know how to add the context menu in Windows Explorer that will run my openLocalHostWebBrowser.bat file when clicked on.
What I need help with is taking that file path that is passed and changing it by removing part of the front of it and prepending my localhost or any URL for that matter, perhaps another one for a production server.
So if the file path passed to my .bat file is like this...
E:\Server\htdocs\labs\php\testProject\test.php
then I need to somehow turn it into this...
http://localhost/labs/php/testProject/test.php
The E:\Server\htdocs\ should be replaced with http://localhost/
I believe your requirement is fixed (E:\Server\htdocs\ should be replaced with http://localhost/). If so, below may help you.
#echo off
set input=%1
Echo.Input was - %input%
set converted=%input:E:\server\htdocs\=http://localhost/%
set converted=%converted:\=/%
echo.Converted to - %converted%
Sample tested output -
D:\Scripts>repl.bat E:\Server\htdocs\labs\php\testProject\test.php
Input was - E:\Server\htdocs\labs\php\testProject\test.php
Converted to - http://localhost/labs/php/testProject/test.php
Cheers, G

Textmate 2 Ruby Run settings for current directory

I have Ruby 2.0.0 and TextMate 2 playing along nicely, after some TM_RUBY settings from this blog post.
However I have:
/Users/koos/Developments/RubyDevs/RubyTests/RubyLearn/Test1.rb
and
/Users/koos/Developments/RubyDevs/RubyTests/RubyLearn/Test2.rb
Test1.rb has File.open("Test2.rb")
In TM 1.5 this worked, whether I open TM at the RubyDevs levels and drill down, or if I open TM at the RubyLearn level.
In TM2 it gets "no such file or directory" if I open at RubyDevs level but is ok if I open at RubyLearn level.
It is also OK if I change to
File.open("/Users/koos/Developments/RubyDevs/RubyTests/RubyLearn/Test2.rb")
This is clearly a settings issue of some sorts.
Any advise on this?
First of all, this has nothing to do with Textmate but with how Ruby handles that file path. So no need to fiddle with TM settings.
You are opening a file relative to the current working directory. If you run Test1.rb from the RubyDevs directory Test2.rb is not present in the current working directory, if you open the file from the RubyLearn directory it is.
To make it work from any directory you need to determine the directory of the Test1.rb file and add the Test2.rb path like this:
file = File.open(File.dirname(__FILE__) + '/Test2.rb')
file.close()
Hope this helps!

Resources