Eva
Eva

Reputation: 861

I am unable to knit/compile .R files in Rstudio

This is what I type in the source pane

x <- c(1,3,2,5)
x
x = c(1,6,2)
x
y = c(1,4,3)
length(x)
length(y)
x+y
ls()
rm(x,y)
ls()
rm(list=ls())
?matrix
x=matrix(data=c(1,2,3,4), nrow=2, ncol=2)
x
x=matrix(c(1,2,3,4),2,2)
matrix(c(1,2,3,4),2,2,byrow=TRUE)
sqrt(x)
x^2
x=rnorm(50)
y=x+rnorm(50,mean=50,sd=.1)
cor(x,y)
set.seed(1303)
rnorm(50)
set.seed(3)
y=rnorm(100)
mean(y)
var(y)
sqrt(var(y))
sd(y)

But when I do any of the three actions mentioned below, the .R file changes

  1. Trying to save the .R file
  2. Trying to knit the file using File Menu> Knit Document
  3. Trying to compile the document using File Menu> Compile Report

On any of these actions, the .R file changes to

x <- c(1,3,2,5) x x = c(1,6,2) x y = c(1,4,3) length(x) length(y) x+y ls() rm(x,y) ls() rm(list=ls()) ?matrix x=matrix(data=c(1,2,3,4), nrow=2, ncol=2) x x=matrix(c(1,2,3,4),2,2) matrix(c(1,2,3,4),2,2,byrow=TRUE) sqrt(x) x^2 x=rnorm(50) y=x+rnorm(50,mean=50,sd=.1) cor(x,y) set.seed(1303) rnorm(50) set.seed(3) y=rnorm(100) mean(y) var(y) sqrt(var(y)) sd(y)

As you can see, the code loses all the formatting. Apart from that, it also get irrelevant characters like \.

My system details are as follows: RStudio Edition : RStudio Version : 1.4.779 OS Version : Windows 10 x64 (build 19042) R Version : 4.0.2 (2020-06-22)

Because of this problem, I have to save all my code as text file in Notepad or any other text editor, so that I can use the same code in my next session. How can I correct this issue in RStudio?

Upvotes: 0

Views: 749

Answers (1)

Eva
Eva

Reputation: 861

As @Paul and @Phil commented, the issue doesn't exist in RStudio 1.2.xxxx or 1.3.xxxx versions. This issue was specific to RStudio daily build version 1.4.779. After the issue was raised in github and RStudio Community Forum, the issue seems to be fixed in the newer versions of RStudio daily builds.

Upvotes: 1

Related Questions