Removing wavy warnings about long lines in R-VSCode - r

I am running R in Visual Studio Code. I would like to get rid off the Lines should not be more than 80 characters.line_length_linter warnings marked as wavy underlines. I would like to get a global effect so that the warnings are removed from all R files I create wherever I want.
Could someone clarify this and this discussions a little. I already tried to put the following line:
linters: with_defaults(line_length_linter=line_length_linter(10000))
in .lintr file I created. I tried both locations R-4.2.2\library\lintr and R-4.2.2\library\lintr\R. In the later one there is the pre-existing lintr file without .. No help, I also tried:
linters: linters_with_defaults(line_length_linter=line_length_linter(10000))
and it didn't help either. I tried to relaunch the VSCode after the changes.
Edit: if I put the .lintr file with the following line into a higher-level folder of the R script I write, the warnings are gone (the lintr package is installed and is working).
linters: linters_with_defaults(line_length_linter=line_length_linter(10000))

Related

R extension on VS Code - keyboard shortcut NOT working

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.

#title Missing name at line 1

I was getting this error when running devtools::document but had no idea how to troubleshoot. The file that popped up on my installed package when I entered ?MyPackage-package did not match the text in MyPackage-package.R at all. I initially suspected it might have been from adding the awesome citation functionality from RDpack, but this was not the culprit. How did I go about ultimately fixing the problem?
The error resulted from incorrect formatting in my PackageName-package.R file.
I had heavily edited the file created by usethis::use_package_doc(), and added all of my roxygen comments Below the default content added by usethis. After looking at the documentation for merTools, I saw that it was ok to have the stuff I understand to be important for roxygen2 to make the .Rd files after and not before all the other roxygen comments.
After moving the stuff created by usethis::use_package_doc() (and not just the NULL line; that was already at the end) to the bottom of the .R file, everything seemed to render fine and this error disappeared.

How to solve this error message in rmarkdown?

I am just starting to explore the rmarkdown package. I don't use Rstudio. I use the default R environment. What I did was as follows.
I created a new R document.
Started typing few lines in rmarkdown format.
Saved the file with Rmd extension.
I saved the file in the working directory.
I installed the pandoc using the pkg file.
I installed 'rmarkdown' package. Loaded the package.
Used the following command to render the Rmd file.
rmarkdown::render("Untitled.Rmd")
I get the following error.
Error in tools::file_path_as_absolute(input) : file 'Untitled.Rmd'
does not exist
I tried all the possible ways such as giving the exact path instead of filename etc. But nothing worked out. I googled the error message and found that none had similar error. Can someone help me with this. What I am missing. What the error message mean?
Most of the time the error file not found is either a type error or a real missing file (as in your case, the real one is named in another way).
In order to discard those possibilities:
Copy the fullpath from your filebrowser.
Make sure the file exists, inside R you could type:
file.exists("/fullpath/to/file")
If that return TRUE and the error persists, then you suspect another thing is going on.

Problems while reproducing Sankey chart example with d3_sankey

I am trying to reproduce simple example with rCharts library to plot sankey chart. I found this example from scratch and tried to reproduce it, however, I came up with some problems.
Firstly I have tried running this code without nothing. Then I found out and realized, that I need d3_sankey in my computer. So, I have downloaded it from here and copied to C:\Users\adomas\Documents\R\win-library\3.0\rCharts\libraries\widgets\d3_sankey.
Then I've tried that unchanged code once more and still got the following error:
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file '/config.yml': No such file or directory
Since that didn't help too, I have tried changing paths from:
sankeyPlot$setLib('libraries/widgets/d3_sankey')
sankeyPlot$setTemplate(script = "libraries/widgets/d3_sankey/layouts/chart.html")
to
sankeyPlot$setLib('C:/Users/adomas/Documents/R/win-library/3.0/rCharts/libraries/widgets/d3_sankey')
sankeyPlot$setTemplate(script = "C:/Users/adomas/Documents/R/win-library/3.0/rCharts/libraries/widgets/d3_sankey/layouts/chart.html")
However, this time, the blank screen in Viewer appeared but no actual Sankey graph and I got the following in console:
Warning message:
In readLines(file, warn = warn, ...) :
invalid input found on input connection 'C:/Users/adomas/Documents/R/win-library/3.0/rCharts/libraries/widgets/d3_sankey/layouts/chart.html
I have tried changing paths and etc, but still something is wrong. And I am not sure if I need to use sankeyPlot$setTemplate at all.
I want to use Sankey chart in my shiny application, but firstly I want to reproduce simply in R. Suggestions would help a lot!
Versions of libraries:
rCharts_0.4.2
igraph_0.7.0
R version: 3.0.2
EDITED:
I have tried this code on different system. And everything works there. Versions of libraries and R are the same and I've copied same documents and just specified full path. I have tried that again on my own computer, but still got the same error yet.
I've experienced the same issues. The solution for me was to upgrade rCharts :
devtools::install_github("rCharts", "ramnathv")
Second, I didn't include the sankeyPlot$setTemplate() line.
Finally, the path in $setLib() should be a direct path (as discribed in the solution of #adomasb or the following line can be used to link directly to the original github:
sankeyPlot$setLib('http://timelyportfolio.github.io/rCharts_d3_sankey/libraries/widgets/d3_sankey')
A downside of this last approach is that internet is always required to run the script.
Alright, eventually it works as it should be.
I just rebooted my system and that's it. However, if anyone would come up with same problem, just be sure you specify direct path, where you placed all necessary files for d3_sankey. Therefore, you rather use
sankeyPlot$setLib('C:/Users/adomas/Documents/R/win-library/3.0/rCharts/libraries/widgets/d3_sankey')
This is wonderful chart type. Good luck!

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!

Resources