.Rmd files open as completely empty - r

When opening .rmd files in RStudio 3.3.2, they show up as completely empty. There is text if I open using Notepad or if I open on another machine. What is going on?
RMD file in question

I had a similar issue with older R files that opened as empty. It turned out that RStudio didn't use the correct encoding as default and therefore wasn't able to read the file (presented the file as empty).
You can make sure that you are using the correct encoding by:
Opening the file in RStudio as you normally would (the file will be empty)
Navigate to File -> Reopen with Encoding...
Select UTF-8 and click OK
UTF-8 will most likely be the encoding you need. You can also choose to set this as the default for all source files.
This issue was also addressed on RStudio Support

In RStudio go to:
Tools
Global Setting
Left hand side "Code"
a. under "Saving" - Default text econding: change to UTF-8

save #Richard N mentioned, save the files with "UTF-8" encoding. Will solve the issue.
Incase you saved the files without encoding, use the open with encoding option under "Files" tab.

Related

Which is the correct encoding for a degree character?

I have a line of code that alters text
temperature<-as.numeric(gsub("°.*","",temp))
R does not like the "°" character. When I save the file it says I need to use a different encoding.
I have tried all sorts of different encodings from the list, but they all save the code in some variation of
temperature<-as.numeric(gsub("??.*","",temp))
My current solution is to open the script in notepad and copy paste the code into rstudio. Which encoding do I need to save a ° in rstudio?
The full solution to this in rstudio was to go to file -> save with encoding -> select ISO-8859-1 -> check the box Set as default encoding for source files. Now the file opens properly with the degree character every time.

R Studio: Opening an RMD file that contains a report, and another of code, but there is no content. Am I missing a package?

I have a report sent to me in the format of an RMD file. Another RMD that contains the code. However, all that I see are empty files when opened. Im using anaconda: Rstudio 3 version 1.1.456 (is this outdated?)
Unless there is a script to open the file?
The .Rmd format is a particular flavor of markdown so you can open the file with any plain text editor to verify that it is not empty and indeed has the code inside.
I have a solution to my problem: For anyone trying to open an Rmd file in the future with similar circumstances.. open the file, while open, Go into "file - Reopen with encoding - UTF-8".

RStudio won't open some text files

Lately I'm having a strange problem with RStudio (v1.3.1056 on Ubuntu 18.04): When I try to open some text files, RStudio refuses with the message file is binary rather than text:
Yet, the file I'm trying to open is definitely a text file. As an example, take this bibtex file:
#misc{test,
author = {test},
year = {2018},
title = {test},
}
When I try to open it with the file name "test.bib", I get the error above. When renaming it to "test.txt" RStudio opens it without complaining. Here the steps as R code:
rstudioapi::navigateToFile("test.bib") # won't work
file.copy("test.bib", "test.txt", overwrite = TRUE)
rstudioapi::navigateToFile("test.txt") # works perfectly
I'm pretty sure that RStudio wouldn't mind the file ending and just try to open files as text no matter what in the past. But now I either have to rename the file or get a different text editor to edit my bib and other files.
As far as I can tell, this is not a problem of Ubuntu marking the file as binary. Otherwise one of these commands would complain, I think:
readLines("test.bib")
system("grep 'misc' test.bib")
The solution to this problem is rather stupid. Apparently it is possible in Linux to include newline characters in your folder name, yet either RStudio or file doesn't like that. I had no idea that my test.bib file was sitting in a folder with a newline character. So the problem can be reproduced with:
bib <- "#misc{test,
author = {test},
year = {2018},
title = {test},
}"
dir.create("test\nfolder")
writeLines(bib, "./test\nfolder/test.bib")
rstudioapi::navigateToFile("./test\nfolder/test.bib") # throws error
While it works when the folder is just called "test folder"! Sorry for wasting people's time, I should have just tested it elsewhere...
You can see the current test of whether a file is text or not here: https://github.com/rstudio/rstudio/blob/d1289249b11e0d12d2be12b3ceb701c41f110cec/src/cpp/session/SessionModuleContext.cpp#L1216. It looks for a recorded MIME type according to the filename extension (and .bib isn't in the list currently, so that will fail).
It then tries to run
file --dereference --mime --brief test.bib
and looks at the result. Maybe your system doesn't recognize test.bib as text/plain? A few other types would also be recognized as text; see the end of that function on github.

Enconding .rmd file mac

Yesterday I was doing an RMD file with a Mac and everything went well, but today, when I reopened the file it looks like this:
D??Pˆ#A????DE????UOØÊË?? Z†é¡Áç€????Z[??¯íñ»•??`#??A??xE??eE??ç#????
f=T??ž Ë^??‚??l[iótó:ò??§FÌ????w72??øø‡ˆDA????U??#?? N??¯??J‡??E????NO´Á??€í??Ç_žË??S|V1™??;¯??îR‘”xe^gP??‹#K??????tO9¢??ì|£æ8??????i;v??7Z??§¬ç˜??/‰RM’ÂmŽlwi3vÇ7œ¡ÊAç????ZE????êJøÀ‡??E??D??AQ??Œ^aD????A[??ô…b›N?????óò†^ƒ®«??Èq??%Z§??Ë®????r#,æ????D??}Q¾ Tçœ??BQ??Œ,^Ž®t??;~??Z†hƒrá/??‡¨EŒ??]Iì«ÁÈ????SO‘Êyç??{~]ë??KôüÍ????nd#Xèñü•??amGo??akG{??jW}—(Ÿ˜
,??Ø&ï¿&ïbN??qô$…òš??6€¦??áY??ͬ??˜,(˜r-,”f}U?? Ë??_å??(Z–??$€ò??§^Ì®????3rÇ/œˆ#E????N??Aô??Í??^€??KQÈŒ??]QìŠÊ[ç¯??î^}??+Dž??\Wƒ??«#üƒ??µoÀa??E??9D????q['ò????‰®N??¤}î*|??
:????B[??ô,…š~5????Y…T›œ
Does someone know how to revert the encoding?
Though I am a Windows user, I have an easy way to make a corrupted file readable: you can reopen the file with whatever encoding you want. First of all, open the file as usual. Then, if you see the file garbled, click File and Reopen with Encoding... button, as shown in the following picture.
Choose Encoding will appear next, so you can choose one.

Corrupted Rmarkdown script: How can I get the Cyrillic characters back?

I was working with a script with lots of Cyrillic characters (throughout chunks and out of them) for weeks. One day I have opened a new Rmarkdown script where I wrote English, while the other document is still in my R session. Afterwards, I have returned to the Cyrillic document and everything written turns to something like this 8 иÑлÑ 1995 --> ÐлаÑÑÑ - наÑодÑ
The question is: Where is the source of problem? And, how can the corrupted script turn to its original form (with the Cyrillic characters)?
UPDATE!!
I have tried reopeining the Rstudio scrip with encoding CP1251, CP1252, windows1251 and UTF8, but it does not work. Certaintly the weird symbols change to another weird symbols. The problem is that I have saved the document with the default encoding CP1251 and windows1251) at the very begining.
Solution:
If working with cyrillic and lating characters, be sure you save the Rstudio script with UTF-8 encoding always, when you computer is windows (I do not know mac). If you close the script and open it again, re-open the file with UTF8 encoding.
Assuming you're using RStudio: Open your *.Rmd file and then try to reopen it "with encoding". Therefore simply use the File-Menu as shown below.
Select "Show all encodings" and choose your specific encoding, I suggest windows-1251 for cyrillic encoding:
Note: Apparently the issue can also occur while at the one time opening the *.Rmd file as "standalone" and at the other time from within an R Project.
Hope that would help.

Resources