Enconding .rmd file mac - r

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.

Related

"The system cannot find the file specified whenever I knit"

Whenever I knit to a PDF in RStudio, the error "The system cannot find the file specified."
Here is the code that I'm using:
##importing data
library(readr)
Quiz1data_2 <- read_csv("C:/Users/erinp/Downloads/Quiz1data-2.csv")
I have restarted RStudio multiple times and I have copied and pasted the exact link that my file is saved to and it's still not working.
What am I not seeing or what am I not thinking?
Some suggestions/questions:
Without knitting, when you run the line reading in the csv, does it work?
Also, are you sure that the error is referring to the data csv? Could it be referring to the (I'm assuming) markdown file you are writing your code in? Have you moved that file since you started working in it?
Are you able to knit other documents to pdf? You need MiKTeX on a windows machine. Does knitting to html work?
I've found R to be a little tricky reading in files. I usually use the base function like this:go to the environment tab>import dataset>from text(base)> (select the file you want, hit open)>(select settings so that the dataframe preview looks right>import. Code that does this will run in the console, and I copy it into my markdown file so that every time it knits, it replicates that successful process.
I figured it out. It's because I forgot to assign a value to an object so it wouldn't knit into a PDF. I made a comment earlier, but it's small so I thought I would add this to the answer section.

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.

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.

.Rmd files open as completely empty

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.

Resources