ASH
ASH

Reputation: 20302

R Code Runs Fine in RStudio but not in Visual Studio

I just ran this in RStudio and it works fine.

Gender <- c("Female","Female","Male","Male")
Restaurant <- c("Yes","No","Yes","No")
Count <- c(220, 780, 400, 600)
DiningSurvey <- data.frame(Gender, Restaurant, Count)
DiningSurvey

Then I try to run it in Visual Studio and it does nothing at all.

If I go to Test > Run > All Tests, I get this: 'There were successful build errors. Would you like to continue and run tests from the last successful build?' There is no last build and no matter what I try, this doesn't work. IF I hit any function key, including F5, F11, or whatever, this doesn't work!! How can I run R code in Visual Studio? It seems like this should be super-simple, but it is very, very, very difficult.

Thanks.

Upvotes: 1

Views: 1170

Answers (2)

In general, R in VS works same a R in RStudio. In other words, F5 does not work since R is not a compiled language and does not have predefined entry point. For example, for debugging you set a breakpoint, then attach debugger, then source file and then call the desired function from R interactive window.

Upvotes: 4

Andrie
Andrie

Reputation: 179418

To run R in Visual Studio, you need the R Tools for Visual Studio (RTVS) plugin.

You can download this at http://microsoft.github.io/RTVS-docs/

This will turn Visual Studio into a capable client that knows how to deal with R.


Once you've installed RTVS, the easiest way to get started is to create a new R project:

\File\New\Project...\New R Project

This will create a new project with templates for R and Rmd files.

You can send code from an R file to the "R Interactive" window by pressing Ctrl+Enter.

You can see this in action by watching the video at https://youtu.be/KPS0ytrt9SA

Upvotes: 1

Related Questions