Unable to open with correct encoding

Hi!

I can't get RStudio to open my script with the correct encoding. I only see gibberish regardless of which encoding I choose. I have also tried to open it in R but that doesn't work either. I really need to open this script! Any ideas?

I have tried opening it in the texteditor, notepad and Word on my Mac. It is an .R file.

The script should be available here: https://gubox.box.com/s/4k011vrk5381hkmmadb9dfbyc1x20c98

I have analyzed the file using the file -I command:
Stefans-MacBook-Pro:downloads stefan.e.oberg$ file -I TwinIVSimulationResults_new.R
TwinIVSimulationResults_new.R: application/x-gzip; charset=binary

What is your file extension ? Can you send your file ?
Have you tried to open it in an editor like notepad++ to see what is the encoding and if it works ?

Without more information, it will be difficult to help you.

Hi
Thanks! The script should be available here:
Script

I have tried opening it in the texteditor, notepad and Word on my Mac. It is an .R file.

I am sorry, I want to believe you, but this does not seem to be an R file, or even a textfile

# Download the file
url <- "https://gubox.box.com/shared/static/4k011vrk5381hkmmadb9dfbyc1x20c98.r"
script <- tempfile()
download.file(url, script, mode = "wb")

#  Let's what is inside 
readLines(script, n = 5)
#> Warning in readLines(script, n = 5): la ligne 3 contient un caractère nul
#> Warning in readLines(script, n = 5): la ligne 5 contient un caractère nul
#> [1] "RDX2"                                                                                           
#> [2] "X"                                                                                              
#> [3] ""                                                                                               
#> [4] "“¼d?á\177¦ÚJžþ?á^"                                                                              
#> [5] "”&Ö›?án(¦žJ?áwt\030\033ª=?á~7Ãïì.?áo8Õèì!?á]5\021žã?á4'Ð9TÍ?á¦äªa×}?áHY\v!d-?ákÇ\022{é\027?á’"
# I can confirm it is not readable in notepad++ either.


# Does not seems to be an R script, or even a text file.
# Can we try guessing the MIME TYPE
library(simplemagic)
get_content_type(script)
#> [1] "???"
# No we can't...
unlink(script)

Created on 2018-07-07 by the reprex package (v0.2.0).

This is also what I get in Notepad++

Does not seem to me an encoding issue. The file does not seem to be a text file. More like a binary of some sort.

Unfortunately, with this current file, I can't help much... :disappointed:

1 Like

Did you take a look at the output application/x-gzip; charset=binary?

$ echo "Some text" > my_file.txt
$ gzip my_file.txt
$ file -I my_file.txt.gz 
my_file.txt.gz: application/x-gzip; charset=binary
$ mv my_file.txt.gz my_file.txt
$ file -I my_file.txt 
my_file.txt: application/x-gzip; charset=binary

I.e. don't trust the file-ending... You'll need to run

$ mv TwinIVSimulationResults_new.R TwinIVSimulationResults_new.R.gz
$ gunzip TwinIVSimulationResults_new.R.gz

and then you should be good to go?

BIG thanks to everyone for trying and for your suggestions!!
Unzipping it didn't help. I saw a flash of the contents the first time I opened it in RStudio the other day before it all turned to gibberish. I guess that was the last I saw of it...
But, I have managed to recreate most of it from backups and hope I didn't miss anything too important. It is a simulation I use for the results in a chapter in a book. The book has been in production for 13 months and it was when I opened it for the last checks before publishing it that this happened...
Thank you all so much anyway!

Given the magic string RDX2, this is likely a saved R object of some form. You might try loading it with load() or readRDS() to recover whatever R objects are serialized within.

It's worth reiterating that this appears to be an R object, not an R script, hence why it looks like a binary mess when you open it within an editor.

2 Likes

Oops. I must have backstabbed myself in the file names. Sorry to cause you all work by careless copy-pasting!

1 Like