I have installed R extension and radian to use R from VS code.
I wanted to run selected line(s) as I do in Rstudio.
Even though it appears to be set among "Keyboard Shortcuts" the shortcut cmd+enter (see pic) doesn't seem to work. Anyone can think of why?
I figured it out!
First a clarification: the issue was only affecting code in *.rmd|*.Rmd files, while normal *.R script were doing OK.
As for the *.rmd files, following the instructions here I added this in my settings.json file:
{
"files.associations": {
"*.Rmd": "rmd"
}
}
Now my shortcut cmd+enter works like a breeze ✅
PS: there may be issues also with conflicting keyboard shortcuts. In fact I deleted some that I have no interest in, but that did not solve it.
Related
I am new to VSCode and trying to use R in VSCode.
I was wondering how to change R assignment operators to the red ones(arrows) as showed in the VSCode website.
Here is the website:
https://code.visualstudio.com/docs/languages/r#_code-completion-intellisense
You need to have a font with ligatures. One of the most common to use is FiraCode. To install it, check here.
Then, in VSCode, go to settings.json and paste the following lines (check the full instructions here.
"editor.fontFamily": "Fira Code",
"editor.fontLigatures": true
After that, close/reopen VSCode, and it should work.
I'm using VS Code and i miss RStudio's ctrl+i to indent lines.
I've read stuff online about LSP and other extensions and formatting with shift+alt+F but all i get is linter.
So, whats the equivalent if is there at all?
Found a solution but there a few things to take note.
First, VSCode notive options are language-agnostic, meaning it can't indent R code 'cause it doesn't understand it. You got to download extensions to make i work.
Extensions required are
Yuki Ueda's R for language support
REditorSupport's R LSP Client
Also, in order to R LSP Client to work, CRAN package {languageserver} is required.
Then, usage. If you're working functions, differently from RStudio in which one can hit ctrl+i and that'd indent that specifically line or selection, this solution works only if one selects the entire function. If you have functions inside another, you gotta indent everything (won't work for just a foo inside another).
ctrl+R no longer works for executing script lines.
This is not a hardware/keyboard problem.
I have also restarted my PC.
I have tried on a different PC.
I have recently switched from using R to using RStudio. I thought this may have something to do with it, so I opened and resaved the script in RStudio, to no effect.
Furthermore, I have created an R-Project folder and have copied the files, including the script in question, into it. Then I started R-Studio and opened the project.
I would like to post my sessionInfo(), but do not know how to do that without executing the command.
Keep in mind that I only use R for stats purposes. I don't know much about informatics or other types of programming etc., so please try to keep it simple for me. Thanks!
In addition to the solution offered above, in Rstudio, Ctrl + Enter does not work if the chunk is broken in .Rmd files.
For example, if you press CTRL + Enter on the following line (2+2), it won't work:
```{r}
2+2
``
The chunk should end three Backtick characters, not two.
The problem was that the script file (for some reason unkown to me) did not have the correct extension (.R). When I added that to the script file extension, it worked fine again.
I've got a strange behavior of qmake while trying to write smth to another file. I read all possible manuals and searched out the internet but found nothing similiar. Closer to the simplest possible code:
!system(echo 1 > d:\1.txt) {
warning(Cant create a file)
}
It doesn't create a file, and it doesn't show a warning, that means that operation succeded. Another example:
var = test string
file = $$absolute_path(d:\1.txt)
message(Variable: $$var and filename: $$file)
!write_file($$pathBat, pathtowrite) {
warning(Cant create a file)
}
This block produces output:
Project MESSAGE: Variable: test string and filename: d:/1.txt
And nothing is said about the fact the file has not been created.
I've already checked the rights to write to the directory: everything seems fine.
Can anybody help me with this?
UPD:
I've found something else: message($$system(echo 1 > 1.txt)) works fine. And this is what makes me cry, because I really don't understand what is going on.
Huh! I found the solution and it may sounds like buy yourself some brain. I thought, that qmake is launched every time the project file is changed (output of message commands proved my thoughts), but it's not really the way things happen in Qt.
I don't know how exactly, but it parses the .pro file, does only some necessary operations, and as I can see system() (which is going to change some file), write_file() commands doesn't seem to be invoked.
The SOLUTION is so much simple: natively launch qmake using the Build - Launch qmake.
I would to change the start up/ logon screen that I get when I first open up R or actually Rstudio. What I would like to have is just the '>' prompt and nothing else.
I know I have seen this on the web before but can't remember what the search phrase was.
I should have added that I am using Ubuntu Linux!
Any suggestions?
Other guys are giving you advice how to stop the messages, I will take it the other way: how to clear the console. You can press Ctrl-L manually. Of course, it would be nice to do this programmatically and place the appropriate command at the end of your system .RProfile. I tried the obvious solution:
cat("\014") # or cat("\f")
but this apparently doesn't work. You can do this:
cat(rep("\n", 50))
which will clean your console, but the cursor is at the last line. Or you may try the solution proposed here (I've not tested it though - please report if it works if you try it):
cls <- function() {
require(rcom)
wsh <- comCreateObject("Wscript.Shell")
comInvoke(wsh, "SendKeys", "\014")
invisible(wsh)
}
On linux console, the following could work:
system("clear")
You can put this line to .bashrc in your home directory or .zshrc if you use zsh.
alias R='R -q'
-q means quiet.
Adding
cat('\f')
to my .First() function in my .Rprofile works for me. I use Rstudio, (Windows 7, build 7601, Service Pack 1, x86)
Create a .Rprofile file that contains:
'cat("\014") # Clear console`
Change "Default working directory ..." in RStudio preferences to the folder that contains .Rprofile.
Update: as of November 2016, this now seems to work in RStudio 1.0.44 cat("\014"). This is what I add to the top of my latest R scripts:
rm(list=ls()) # removes all objects from the environment
cat("\014") # clears the console
credit to #TMS for the solution
Note: it leaves the .Last.value as NULL in the environment, but I'm OK with that
There's a function '.First' that gets executed when you enter the console.
.First <- function(){
cat("\n")
}
This could do it.