"/content?title=....htm not found" error message - r

I'm trying to view my data in RStudio and I get the above strange message, what is that and how do I fix whatever problem there is? I can still work with the data, I just can't see it.
I haven't done anything special, it just "happened". I just keep trying View(df)... and now all of a sudden my data frame is an endless column of 1's, although the View window states, true enough, that df is "30 observations of 2 variables".

I also had this problem several times. For me it always helped to quit and restart RStudio. You might try this.
EDIT:
Normally when quitting RStudio without saving your workspace manually before, you should get a prompt asking you
Save workspace image to $pathToYourWorkspace ?
If this is not the case maybe u have no writing permission in your selected workspace folder. Be sure about that first. If you have the permission you could try saving your workspace manually by entering
save.image('$pathToYourWorkspace/.RData')
Can you try accessing your previous entered commands in the console by using arrow up key? Does it work?
Do you have a file called .Rhistory in your workspace?
If not check Options if u have it activated (Tools -> Global Options -> General) and then check 'Restore .RData into workspace at startup' and 'Always save history ...'
You could also check if u have the latest Version of RStudio installed.

Related

In styler package of tidyverse, style_text prompts user input when first run

> packageVersion('styler')
[1] ‘1.3.2’
> style_text("A <- 1")
The R.cache package needs to create a directory that will hold cache files. It is convenient to use ‘C:\Users\A0765618\AppData\Local\R\R.cache’ because it follows the standard on your operating system and it remains also after restarting R. Do you wish to create the 'C:\Users\A0765618\AppData\Local\R\R.cache' directory? If not, a temporary directory (C:\Users\A0765618\AppData\Local\Temp\Rtmp6z4Eit/.Rcache) that is specific to this R session will be used. [Y/n]:
How can I run this functionally initially without this prompt? Can I set the answer to the prompt prior to calling? For example, how can I set it to n so that no prompt is needed?
This function will be called in a shiny app, so this prompt, which appears in the console will cause a bug.
TLDR;
put this before you call {styler} where the directory should already exist:
options(R.cache.rootPath = '/path/to/your/cache/dir')
You have the following options:
Deactivate the cache altogether
First of all, you can get rid of the caching problem by deactivating it altogether with styler::cache_deactivate(). Then, the prompt should not show up. To make this permanent, put this line in your .Rprofile.
Setting up the cache programmatically
However, if you want to benefit from the speed up the cache brings in your setting, you can set it up programmatically. I am just updating the docs for it (if you have comments please let me know):
In some cases, you want to avoid the interactive prompt described above. In that situation, you can set the path to the cache with the R option R.cache.rootPath or the environment variable R_CACHE_ROOTPATH to an existent path before you call the {styler} API. This should avoid the prompt. R.cache::setCacheRootPath("/path/to/cache") is also programmatic but will probably give the prompt anyways if called interactively.
So just do options(R.cache.rootPath = '/path/to/your/cache/dir').
You can also silence the pretty color warning (if you don't want to install it) with setting the option styler.colored_print.vertical as described in help(print.vertical, package = 'styler').
In addition, there is a styler.quiet option in styler > 1.3.2 but it likely won't have any impact because what you are seeing is directly coming from {R.cache}.
R.cache::setCacheRootPath(getwd())
Does indeed produce an undesirable message and prompt:
The R.cache package needs to create a directory that will hold cache files. It is
convenient to use '<xxxx>/Caches/R/R.cache' because it follows the standard on your
operating system and it remains also after restarting R. Do you wish to create the
'<xxxx>/Caches/R/R.cache' directory? If not, a temporary directory (/var/folder
/47/4_fn5xyx01b8_8bnyn8cpv3c0000gn/T//RtmpdO3NGa/.Rcache) that is specific to this
R session will be used. [Y/n]:
But, taking the hint in the prompt,
R.cache::setCacheRootPath("<xxxx>/Caches/R/R.cache")
runs without error or warning.
Then, after installing the prettycode package,
style_text("A <- 1")
produces
A <- 1
without message or warning.
Is it worth dropping a note to tidyverse asking for a styler.silent option?

Why doesn't restarting R with Ctrl-Shift-F10 clear my environment variables?

I have RStudio working on two different machines: mine and a colleague's.
When I restart R in RStudio with the Ctrl-Shift-F10 shortcut, all my global environment variables go away. Not so for my colleague's, who frequently puts rm(list=ls(all=TRUE)) in our shared code.
Is there an optional parameter somewhere, so that restarting R always clears environment variables?
Disclaimer: this has 100% effectiveness based on a sample size of 5 so far (validated by OP & Badger), but I'm recording it for posterity since other forums where I've seen similar questions (example 1, example 2) don't even have that. :)
Solution: Go to Tools / Global Options / General & change the "Save workspace to .RData on exit" dropdown option to "Never".
Possible interpretation: Even if you chose the 'Ask' option in "Save workspace to .RData on exit", Ctrl-Shift-F10 shortcut won't ask before the session gets restarted. But unless you explicitly chose to NEVER save workspace on exit, RStudio will keep it somewhere just in case. (I'm not sure where, though. There's no .RData file in my working directory corresponding to the restored environment...)

R studio List and Dataframes auto name completion not working anymore

Suddenly R Studio stopped auto completing my list and data frame contents when entering mylist$ then pressing Tab. The result message I get is
No matches
I tried that on very simple lists or data frames like:
simpledataset <- data.frame(a=rep(0,100),b=rep(1,100))
However, when I load the dataset Mtcars, it correctly shows the column names.
I reset %localappdata%\RStudio-Desktop by renaming it, but didn't change anything.
Any idea of what could be the cause of that?
This sounds like a bug in the autocompletion system that is occasionally triggered when certain packages are loaded, or the byte-compiler optimization setting is increased. You might try checking a few things:
What is the value of compiler::getCompilerOption("optimize")? Autocompletion is known to fail when this value is equal to 3 in the current RStudio release (v0.99.896). You can try running compiler::setCompilerOptions(optimize = 2) to resolve this.
What packages do you have loaded? You can try loading packages one-by-one to see which affects RStudio's ability to provide autocompletions.
Finally, there should be a fix for this in the preview version of RStudio -- you can try it out at https://www.rstudio.com/products/rstudio/download/preview/.
Go to Tools>Global Options... and set autocomplete there.

Extract what was printed deep in the R console

When I execute commands in R, the output is printed in the console. After some threshold (I guess, some maximum number of lines), the R console no longer shows the first commands and their output. I cannot scroll up that far because it is simply no longer there.
How can I access this "early" output if it has disappeared from the console?
I care mostly about error messages and messages generated by my own script. I do use a script file and save my results to a file, if anyone wonders, but this still does not help solve my problem.
(I have tried saving the R workspace and R history and then loading it again, but did not know what to do next and was not able to find what I needed...)

Starting R and calling a script from a batch file

I have an R-based GUI that allows some non-technical users access to a stats model. As it stands, the users have to first load R and then type loadGui() at the command line.
While this isn't overly challenging, I don't like having to make non-technical people type anything at a command line. I had the idea of writing a .bat file (users are all running Windows, though multi-platform solutions also appreciated) that starts R GUI, then autoruns that command.
My first problem is opening RGui from the command line. While I can provide an explicit path, such as
"%ProgramW6432%\R\R-2.15.1\bin\i386\Rgui.exe"
it will need updating each time R is upgraded. It would be better to retrieve the location of RGui from the %path% environment variable, but I don't know an easy way to parse that.
The second, larger problem is how to call commands for R on startup from the command line. My first thought is that I could take a copy of ~/.Rprofile, append the extra command, and then replace the original copy of the file once R is loaded. This is awfully messy though, so I'd like an alternative.
Running R in batch mode isn't an option, firstly since I can't persuade GUIs to display themselves, and secondly because I would like the R console available, even if the users shouldn't need to use it.
If you want a toy GUI to test your ideas, try this:
loadGui <- function()
{
library(gWidgetstclck)
win <- gwindow("test")
rad <- gradio(letters[1:3], cont = win)
}
Problem 1: I simply do not ever install in the suggested default directory on Windows, but rather group R and a few related things in, say, c:/opt/ where I install R itself in, say,c:/opt/R-current so that the path c:/opt/R-current/bin will remain constant. On upgrade, I first renamed to R-previous and then install into a new R-current.
Problem 2: I think I solved that many moons ago with scripts. You can now use Rscript.exe to launch these, and there are tcltk examples for waiting for a prompt.
I have done similar a couple of times. In my cases the client was using windows so I just installed R on their computer and created a shortcut on their desktop to run R. Then I right click on the shortcut and choose properties to get the propertiest dialog. I then changed the "Start in" folder to the one where I wanted it to run from (which had the .Rdata file with the correct data and either a .First function in the .Rdata file or .Rprofile in the folder). There is also a "Run:" option that has a "Minimized" option to run the main R window minimized.
I had created the functions that I wanted to run (usually a specialized gui using tcltk) and any needed data and saved them in the .Rdata file and also either created .First or .Rprofile to run the comnand that showed the gui. The user double clicks on the icon on the desktop and up pops my GUI that they can work with while ignoring the other parts.
Take a look at the ProjectTemplate library. It does what you want to do. It loads used libraries from a batch file an run R files automatically after loading as well as a lot of other usefull stuff as well...
Using the answer from https://stackoverflow.com/a/27350487/41338 and a comment from Richie Cotton above I have arrived at the following solution to keeping a script alive until a window is closed by checking if the pointer to the window is valid.
For a RGtk2 window created and shown using:
library(RGtk2)
mainWindow <- gtkWindow("toplevel", show = TRUE)
Create a function which checks if the pointer to it exists:
isnull <- function(pointer){
a <- attributes(pointer)
attributes(pointer) <- NULL
out <- identical(pointer, new("externalptr"))
attributes(pointer) <- a
return(out)
}
and at the end of your script:
while(!isnull(mainWindow)) Sys.sleep(1)

Resources