R View() function does not show data frame - r

I am using R (Version 3.1.2) with RStudio (Version 0.98.1091) on a Linux Ubuntu machine. I have a csv file loaded in variable:
rr <- read.csv("/home/user/seconds.csv")
When I call View(rr) I expect to open a new tab and display the CSV data in the rr variable. However, it opens a new tab called rr and it displays the following message.
/content?title=rr&file=94af460bd6644d3aaac734d585046c4f.htm not found

The View function is from package 'utils' which is not supported by the version of R you are using.

I am on a x86_64-w64-mingw32 system with R version 3.4.1, but I want to share a simple solution to get View working again in my case.
Following the step 4 of advice from Tian on Rstudio support (https://support.rstudio.com/hc/en-us/community/posts/115007743908-The-Rstudio-view-not-work-just-blank-), I entered:
install.packages("dplyr", dependencies = TRUE)
Now it works.

Related

ggplot2 plot function returns NoneType object with rpy2

I have a simple script that creates a ggplot2 scatter plot using rpy2. However, the figure is not being displayed. The returned plot object is NoneType. Here is the script:
from rpy2 import robjects
import rpy2.robjects as ro
from rpy2.robjects.lib import grid
from rpy2.robjects.packages import importr, data
import rpy2.robjects.lib.ggplot2 as ggplot2
rprint = robjects.globalenv.find("print")
stats = importr('stats')
grdevices = importr('grDevices')
base = importr('base')
datasets = importr('datasets')
grid.activate()
mtcars = data(datasets).fetch('mtcars')['mtcars']
gp = ggplot2.ggplot(mtcars)
pp = gp + ggplot2.aes_string(x='wt', y='mpg') + \
ggplot2.geom_point()
print('type(pp):',type(pp))
fig = pp.plot()
print('type(fig):',type(fig))
pp.plot()
I am able to save the figure to a png file, so most of the code is working. While troubleshooting this, I've tried using several versions of rpy2 with various results:
Versions 3.0.1 and 3.0.2 -- Figure flashes, program crashes and plot object is NoneType
Version 3.0.3 -- Empty canvas flashes, program crashes and plot object is NoneType
Versions 3.0.4 and 3.0.5 -- Figure flashes, program crashes and plot object is NoneType
Versions 3.1.0 and 3.2.0 -- The figure is not displayed and plot object is NoneType
Versions 3.2.1 to 3.2.4 -- rpy2 fails to install with pip
I have also read the thread here and followed the links suggested there but I have not been able to adapt the suggested actions to my problem.
For completeness, here are details of the environment I am using: Python 3.7.5, R version 3.6.0, MacOS Catalina Version 10.15.2.
More details to describe "fails to install" would help to guess what is happening with Catalina. On Github Actions, the latest OSX is High Sierra (10.13) and both installs and tests work there: https://github.com/rpy2/rpy2/runs/378570566
Otherwise, your code does not seem to make use of grdevices (or any of the other R pacakges imported through importr()). R may use "static" graphical devices (e.g., PNG file) or "interactive" graphical devices (e.g., X11, Quartz on OSX).
See https://rpy2.github.io/doc/v3.2.x/html/graphics.html#graphical-devices for more info.
Interactive devices may require to process the event loop to update (see
https://rpy2.github.io/doc/v3.2.x/html/interactive.html#r-event-loop), although a program crash is not expected when not doing so.
You could try identify what is the graphical device opened by default on your system (unless there is already an open device R will open a device of the default type) as a first step toward identifying what the issue is.

missing R Data Editor window with RStudio on Mac

I am learning R with RStudio on Mac. When trying the following code:
mydata <- data.frame(age=numeric(0),
gender=character(0), weight=numeric(0))
mydata <- edit(mydata)
if I use R(GUI) on Mac, it works fine.
R data editor popup from R on Mac
But if I run the same code from RStudio on the same Mac, there is no window and the RStudio is stuck.
Anybody can help?
R studio doesn't support edit function. Instead you can use library like 'editData' (https://cran.r-project.org/web/packages/editData/README.html).

How to get rid of side effect of tcltk2 package?

After working with the tcltk2 library to create a GUI window in R, when I revert to using a window produced with a package which depends on tcltk (without the 2), I get this error message on Windows 7:
Error in col2rgb(col) : invalid color name 'SystemButtonFace'
It must be that tcltk2 changes some underlying options for working with GUIs in R, because the error message is absent prior to loading tcltk2. I am working with the following version of R:
R version 3.1.0 (2014-04-10) -- "Spring Dance"
Is there a way to deal with this side effect (i.e., remove it)?
I tried to simply detach the tcltk2 package (which is a supplement to the tcltk package), but that doesn't do it.
I also tried replacing the colours in the GUI window that generated the error messages with R colour names like "red" and "blue" (instead of colours like #CCCFFF).
Any help would be greatly appreciated.
Thanks,
Isabella
It is not just an annoyance - it prevents R from properly displaying subsequent GUI windows.
I've put together some example R code. The code uses the PBSmodelling package to create an R GUI window (where the package depends on tcltk but not on tcltk2, both of which are R packages). The GUI window thus created is properly displayed in R. However, after loading the tcltk2 package in R and trying to display the same window again, I get the error message:
Error in col2rgb(col) : invalid color name 'SystemButtonFace'
To give you some context, most of the R GUI windows I've written for my project so far rely on PBSmodelling and work fine. I only need to use tcltk2 to create a couple of windows for the project, but these windows cannot (at least at the moment) be integrated with the majority of the other windows because of the above mentioned error message.
Here is the R code that will reproduce the error message:
## install & require PBSmodelling package
## for creating R GUI windows
install.packages("PBSmodelling")
require(PBSmodelling)
## function to plot a sinusoid (to be called by GUI window)
myPlot <- function() {
getWinVal(scope="L");
x <- seq(0,500)*2*n*pi/500;
plot(x,sin(x),type="l");
}
## create an R GUI window with PBSmodelling
winStr=c( "window title=Simple",
"entry name=n value=5",
"button function=myPlot text=\"Plot sinusoid\"")
## display R GUI window created with PBSmodelling
createWin(winStr,astext=TRUE)
## install & require tcltk2 package
install.packages("tcltk2")
require(tcltk2)
## try to display R GUI window created with PBSmodelling,
## this time after loading the tcltk2 package in R
createWin(winStr,astext=TRUE)
## Error message:
## Error in col2rgb(col) : invalid color name 'SystemButtonFace'
If you have any ideas for resolving this issue, please let me know.
Many thanks,
Isabella

R Package tm.plugin.webmining does not work with R 3.1.0 (but does with R 2.1.5)

I am using R 3.1.0, along with the tm.plugin.webmining package (within RStudio). Packages are installed fine (along with all dependencies) and I can load the library.
When I try to run a basic test however:
yahoocorpus<-WebCorpus(YahooNewsSource("Microsoft"))
I get:
Error in get(name, envir = asNamespace(pkg), inherits = FALSE) :
object '.Source' not found
This does not occur if I point RStudio to R 2.1.5
I have looked online but not found any resolution of the issue (though somebody did suggest a hack of the source code). It would be great to understand exactly what is causing the problem (and what has changed between versions to make this happen (I also tried 3.0.1, and that also does not work)
Thanks again,
Alan
I think that function WebCorpus does not exist in last version of TM package. Check the doc here!
You have 3 possibilities : DirSource, VectorSource, or DataframeSource.
You can check the source on R with:
{r}
library(tm)
getSources()
Which should give you :
[1] "DataframeSource" "DirSource" "URISource" "VectorSource" "XMLSource"
Cyrille

source code for autocompletion in R run in terminal

I would like to study the autocomplete code of R, when R is run in a terminal. For example, if you run R from the terminal and type lm( and then tab, R will give you the arguments of lm.
Dirk's answer here suggests that autocompletion of R is supported by the codetools package which is in base R:
Is it possible to get code completion for R in Emacs ESS similar to what is available in Rstudio?
However, I can't find where in that package it adds support for autocomplete. I grepped for 'completion' and came up empty.
The completion code is actually in the base instalation in the utils package. You can view everything associated with it (for the devel version) on R's SVN server:
http://svn.r-project.org/R/trunk/src/library/utils/R/completion.R
This code should be read in conjunction with ?completion.

Resources