Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RStudio does not display any output in console after entering code

Tags:

r

The problem is that when I run the code, there's no return in the console; I mean it does run the code, but does not return any output.

For example, if I write

v <- c(1, 2, 3, 4, 5) v 

I would expect in return

[1] 1 2 3 4 5 

But it's not working.

I have version RStudio Version 0.98.1079 and R Version 3.1.1

like image 618
Alexis Otoya Carpio Avatar asked Oct 21 '14 20:10

Alexis Otoya Carpio


People also ask

How do I view output in RStudio?

By default, the RStudio IDE opens a preview window to display the output of your . Rmd file. However, you can choose to display the output in a dedicated viewer pane. To do this, select “View in Pane” for m the drop down menu that appears when you click on the “Run Document” button (or “Knit HTML” button).

Does RStudio display R console?

Interacting with RThe console window (in RStudio, the bottom left panel) is the place where R is waiting for you to tell it what to do, and where it will show the results of a command. You can type commands directly into the console, but they will be forgotten when you close the session.

How do I show the console in R?

Start R by double-clicking on the R icon on the desktop, or by clicking on the R icon in the start menu. The R graphical user interface (GUI) will open, containing a single window called the command or console window. The greater-than sign ( > ) is R's "prompt;" it indicates that R is ready for you to enter commands.

How do I run code in RStudio console?

To execute the line of source code where the cursor currently resides you press the Ctrl+Enter key (or use the Run toolbar button): After executing the line of code, RStudio automatically advances the cursor to the next line. This enables you to single-step through a sequence of lines.


2 Answers

I was wondering if you had been doing a tutorial where they were demonstrating the sink function and you hadn't gotten to the point where it was reversed.

> sink('out.txt')  # diverts all output to a disk file > v <- c(1,2) > v       # output went to file > sink()  # sets the output back to the console > v [1] 1 2 

Another way would be to call closeAllConnections:

> sink('out.txt') > v > v > closeAllConnections() > v [1] 1 2 

To address the lack of response with a "+" showing at the Rstudio console ... that is a sign that the R parser "thinks" the entered text has not completed a full R command. It may indicate that you haven't typed a closing bracket or parenthesis. If typing one or two of those is unsuccessful and you keep getting mor +'s then you may be successful with typing the [esc]-key. If it is showing up immediately after a restart then you should check your code for correctness and make sure that the .Rdata file is deleted from your working directory. If you don't know what that means then you may need to search for the methods appropriate to your operating system. You could also have an error in the code of one of your .rprofile files.

In any case this has nothing to do with Rstudio per se and everything to to with the typical behavior of an R console session.

like image 195
IRTFM Avatar answered Oct 01 '22 12:10

IRTFM


Do the lines still start with a "+"? It is also possible you forgot to close the brackets of a function. Try "}".

like image 23
mike Avatar answered Oct 01 '22 11:10

mike