how to permanently save options(dplyr.width = Inf) in Rstudio? - r

In Rstudio and the dplyr package :
> save options(dplyr.width = Inf)
helps to visualize ALL columns in a Data Frame.
Great!
But this useful saved Options setting,
vanishes when you quit the current Rstudio session.
Next time you start Rstudio, it's gone...
Q:
How to permanently save:
options(dplyr.width = Inf) in Rstudio?
(so that the saved option setting
is available in ALL my future Rstudio sessions)?
Thanks!
- Ubuntu Linux 12.04 (32-bit)
- Rstudio v: 0.99.441 + R v: 3.2.0 (2015-04-16)
- Pale Moon 25.5.0 and FF 37.0.2

Related

RStudio session aborts when I run gRbase::stepwise function (undirected graphs)

I'm doing an R project on RStudio (RStudio 2021.09.1+372 "Ghost Orchid" Release for Windows), (R version 4.1.2).
I'm working on Windows 10 x64.
I want to create an Undirected Graph from a dataset:
library(gRbase)
library(gRim)
library(gRain)
data(BodyFat)
BodyFat <- BodyFat[-c(31,42,48,76,86,96,159,169,175,182,206),]
BodyFat$Age <- sqrt(BodyFat$Age)
BodyFat$Weight <- sqrt(BodyFat$Weight)
names(BodyFat)[names(BodyFat) == 'BodyFat'] <- 'BodyFatPerc'
gRbodyfat <- BodyFat[,2:15]
graph.MyGraph <- cmod(~.^., data = gRbodyfat)
AIC.MyGraph <- gRbase::stepwise(graph.MyGraph)
I'm still exploring RStudio and graphical models, so I run these lines from the console, one by one.
When I run the last line of code, R session aborts and I get the following pop-up message:
I've also tried the following lines of code (I changed the last line):
library(gRbase)
library(gRim)
library(gRain)
data(BodyFat)
BodyFat <- BodyFat[-c(31,42,48,76,86,96,159,169,175,182,206),]
BodyFat$Age <- sqrt(BodyFat$Age)
BodyFat$Weight <- sqrt(BodyFat$Weight)
names(BodyFat)[names(BodyFat) == 'BodyFat'] <- 'BodyFatPerc'
gRbodyfat <- BodyFat[,2:15]
graph.MyGraph <- cmod(~.^., data = gRbodyfat)
AIC.MyGraph <- stepwise(graph.MyGraph)
but I get the same problem. I tried three or four times running those lines of code, R aborted everytime.
My gRbase, gRim, gRain, Rgraphviz and RBGL libraries are in the home folder:
C:/Users/MyUser/Documents/R/win-library/4.1
Any advice?
EDIT:
I've tried uninstalling/reinstalling R, Rtools, RStudio, reinstalling libraries, updating them, I've tried launching RStudio as Administrator, I've tried changing computer.
The last thing I tried is this:
uninstalling R, Rtools and RStudio
deleting .RData and .Renviron files in the Documents folder
deleting all libraries
downloading R (latest version) from CRAN webpage and installing it as Administrator
downloading Rtools (latest version from webpage) and installing it as Administrator
creating the .Renviron file as described here
downloading RStudio (latest version from webpage) and installing it as Administrator
installing BiocManager as described here (when asked to update Matrix library I said NO, I thought it could be the problem)
installing gRbase, gRim, gRain libraries as described here (when asked to update fansi library I said NO because it said "There are binary versions available but the source versions are later", I thought it could be the problem)
Tried again the lines of code
Still got the problem, R session aborted again.
A friend of mine doing a similar project used gRbase::stepwise function, so I inserted his code in the console and the function worked. So I think the problem might be the object of the function, graph.MyGraph. The cmod function works fine, so maybe there's a problem with gRbodyfat, which is used to build graph.MyGraph.
If I run these lines (I tried changing the dataset, I used BodyFat instead of gRbodyfat):
graph.MyGraph <- cmod(~.^., data = BodyFat)
AIC.MyGraph <- gRbase::stepwise(graph.MyGraph)
I get the following error:
Error in dim(res) <- c(NSEL, NSET) :
dims [product 210] do not match the length of object [14]
Don't know what to do.
EDIT:
I've tried debugging gRbase::stepwise function and I get this:
The problem appears to be the iModel function.
EDIT:
I've discovered that if I use graph.MyGraph <- cmod(~.^1, data = gRbodyfat) the gRbase::stepwise function works fine.

How to call View() / utils::View() in a function as part of a package?

I am writing a function for a package that ends with a call to utils::View(). The aim of the function is to do some data wrangling and then open the dataset in the Rstudio data viewer with View(). If I define the function in the global environment it works fine. As an example (skipping the data wrangling part):
foo <- function(x) {
View(x)
}
foo(mtcars)
opens the dataset mtcars in the data viewer. However, once I put it in my r package and call the function as part of that package it does issue the following error:
"Error in .External2(C_dataviewer, x, title) : unable to start data viewer
In addition: Warning message:
In utils::View(mtcars) : unable to open display"
I have tried to use utils::View() or simply View(), without success. Also, I have tried it with XQuartz uninstalled and with XQuartz installed and couldn't make it work.
I am using Rstudio version 1.0.153 and
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
I am grateful for any hints on how to resolve this!
Try using View(df) instead utils::View(df)
or try restarting the session (Ctrl +shft +F10)
then again using View(df)
or use dpylr to convert it into a table then use glimpse
-----------------------Code-------------------------------------------
install.packages("dyplr")
dplyr::tbl_df(mtcars) #to convert data to table class
dplyr::glimpse(mtcars)

Why is locator() broken in RStudio?

Does anyone know how to fix when RStudio is breaking the locator() function? If I plot
plot(1:10)
then use locator() to click on the same points (1:10), this is what I get after I click the Finish button.
locator(type = 'p', col = 'red')
$x
[1] 1.265369 2.226131 3.172336 4.147655 5.064746 6.040065
[7] 6.986270 7.947032 8.893237 9.868556
$y
[1] 1.437224 2.361029 3.265178 4.169328 5.093133 5.997282
[7] 6.901432 7.825237 8.729386 9.633536
However, if I do the same thing in the R GUI rather than RStudio, then it works just fine:
I've tried restarting my session, using dev.off(), and restarting RStudio but the problem persists. Am I missing something simple here, or maybe it's a bug in RStudio?
R version 3.3.1
RStudio 0.99.903
Mac OSX 10.11.6

How to display Markov Chain plots in Rstudio (markovchain package)

Latest Rstudio and latest R ( in Ubuntu Linux 12.04 - 32bit ).
Most plots will display OK in my Rstudio [Plots] pane.
But some Markov Chain plots throw an Error and don't display.
Here's a very simple example code:
library(markovchain) #loading the package
myMatr<-matrix(c(0,.2,.8,.1,.8,.1,.3,0,.7),byrow=TRUE,nrow = 3)
## defining a transition matrix
rownames(myMatr)<-colnames(myMatr)<-c("a","b","c")
myMc<-as(myMatr, "markovchain")
plot(myMc) # <== Error message starts after this...
gives this Rstudio Console Error:
(and no plot is displayed in Rstudio)
"Error in cut.default(x, binsToUse, labels = FALSE, include.lowest = TRUE, : 'x' must be numeric"
Yet, exactly the same R commands (as above)
work fine in "stand-alone" R 3.2.3! (outside of Rstudio).
And the Markov Chain plot is displayed ok in a new R-window...
Q:
- Is there an easy way/command to tell Rstudio
that I want certain plots
to open in a new R window (just like in pure R),
and NOT in the Rstudio Plot pane?
- Or some other easy solution?

ggvis, Error in normalizedPath()

I am running one of the "interactive" examples from the ggvis webpage (http://ggvis.rstudio.com/ggvis-basics.html#introduction) and I obtain an error.
I loaded the ggvis, dplyr and shiny packages.
Here is the code that I ran:
mtcars %>% ggvis(~wt) %>% layer_histograms(binwidth = input_slider(0, 2, step = 0.1))
And here is the output that I get.
Showing dynamic visualisation. Press Escape/Ctrl + C to stop.
Error in normalizePath(directoryPath, mustWork = TRUE) :
path[1]="/Builds/CRAN-QA-Simon/packages/mavericks-x86_64/Rlib/3.1/ggvis/www/ggvis": No such file or directory
I am using RStudio Version 0.98.507, and R version 3.1.0; Platform: x86_64-apple-darwin13.1.0 (64-bit).
I just found a similar thing trying to run a shiny app from RStudio.
My workaround was to devtools::install_packages("rstudio/ggvis").
I'll put a link to this from the ggvis google group.
Hope this helps

Resources