how to fix errors in multiple .json files in one step? - r

I am trying to load a local json file in R. I am using a package called Sofia that includes the json library. I also tried other packages like rjson and the RJSONIO packages but I get the same error
error in ProcessFiles(File=File), unexpected character E.
This is example code when I use the a local package Sofia:
data<-ProcessFiles(file="data1.json",method="Sofia.method")
When I apply the same package to some old .json files it works normally without error. I tried to change the encoding of the file to UTF-8 but the error persists. The file encoding is ANSI Can anybody help with this?
I ran the online linter and I seemed to discover the error however I want to fix these syntax errors in multple json files in one step, does anybody know how?

Related

Error message "Error: openxlsx can only read .xlsx or .xlsm files" in R 4.1.3

I have a script I was using a few months ago, and I was asked to re-output it using new source data. Now I get the message "Error: openxlsx can only read .xlsx or .xlsm files."
Of course, it IS an .xlsx file.
Not only that, I went back and ran the same script on the old source file (which worked), and...I get the same error!! I haven't changed any code, but my version of R has been updated by the administrators from 3.6 to 4.1.3 (I work in a virtual environment). I have confirmed that openxlsx version 4.2.5 is installed.
I've seen in other posts that people recommend using other packages to read xlsx files. That is not an ideal option here for administrative reasons (getting permission to install new packages can be very time-consuming and may blow deadlines), and I've started pursuing that option, but in the meantime, does anyone have any ideas?
Unfortunately, changing the format (i.e. exporting as csv and using read.csv) is also not an option, because we're auditors and doing that will break the audit trail.
OK, a colleague of mine solved the problem.
The source file has the extension ".XLSX". In order for openxlsx to read the file, you have to change the extension IN THE CODE to ".xlsx" (in my case at least, I didn't even have to change the actual extension of the file--just the quoted reference in the code), although other colleagues say they have had to do this.

What's the reason that readRDS doesn't seem to work in Windows?

I'm trying to make the my code portable to Windows and realized that even though I use file.path to create paths still the readRDS function won't work, for example:
file.exists('C:/temp/HarvardX-Skillability/data/rds/Users.rds')
> TRUE
readRDS('C:/temp/HarvardX-Skillability/data/rds/Users.rds')
> Error in readRDS("C:/temp/HarvardX-Skillability/data/rds/Users.rds") :
error reading from connection
I also tried:
file.exists('data/rds/Users.rds')
> TRUE
readRDS('data/rds/Users.rds')
> Error in readRDS("data/rds/Users.rds") : error reading from connection
Why is that? and how can I fix it? In Ubuntu 18.04 works perfectly ...
The problem seems to be with downloading/cloning the files from GitHub. After running git clone on your repository, when I open my local copy of Tags.rds in a text editor I see this:
version https://git-lfs.github.com/spec/v1
oid sha256:b4a2cb3775126a3895e9533ef9ef4ad786b2021cfd1660b07028fbef85b025bb
size 641098
(this is the entire contents of the file). Furthermore, running file Tags.rds (in a Terminal on MacOS) reports Tags.rds: ASCII text. (All of the .rds files are like this.)
The GitHub web interface confirms that your files are OK on the repo:
This question looks related. After installing Git LFS and running git lfs pull, I get the full file downloaded (and readRDS() seems to work fine).
The culprit to the OP was something really unexpected, I also didn't provide the information for it because I couldn't suspect this was the issue.
The problem was those files were being downloaded automatically using download.file(url, filePath, extra="L") and in Windows this is known to cause issues with binary files that are not the expected ones. This is why the rds files were unrecognizable.
I found out while building exception handling recovery code that was looking to download the same files from a Dropbox folder and then came to the same issue, therefore it wasn't because of Git LFS.
The OP solution was to add the argument download.file(..., mode="wb").
See the question R trouble unzipping file under Windows

workspace cannot be loaded in server, file has magic number 'RDX3'

I've been looking through other SO posts and I've seen that people had a similar problem to mine before. However, in my case when I load my RData workspace in RStudio it works just fine. However, when I try to load it in the server I get the following error:
Error in load(file = "/home/ubuntu/myfile.RData") :
bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file ‘myfile.RData’ has magic number 'RDX3'
Use of save versions prior to 2 is deprecated
I've loaded similar RData files in the server before and it always worked fine. The same file is loaded without any problems in RStudio as I said, but somehow the server doesn't like it
Did you update R in your computer recently? If you did, from R 3.5.0, RData are saved using version 3 by default (RDX3). If you have an earlier version of R in your server, you probably need to save your data using the right version for your server (updating R in your server is another option). Please check the option version in the help of the save command to learn how to do that.

Determine Path Used by R (RStudio) After file.choose()

Is there a way to determine what file path was used after loading a file into RStudio using file.choose()? I was trying to use an absolute file path to load a file, to which RStudio tells me:
Error: `path` does not exist:
I suspect this is occurring because I may have done some damage to my R setup recently (I had issues after installing the latest R, and tried to troubleshoot with online support to correct my .Rprofile and .Renviron files, but I am NOT a programmer). So now R is not recognizing the absolute path to my file, and I'm forced to use file.choose() as a workaround. Ideally, I'd like to see what path file.choose() used so that I can
A) use the correct path reference, and
B) have a better sense of what is going on with my R setup
Any suggestions?

R: Use of save versions prior to 2 is deprecated with a RDA file [duplicate]

I've been looking through other SO posts and I've seen that people had a similar problem to mine before. However, in my case when I load my RData workspace in RStudio it works just fine. However, when I try to load it in the server I get the following error:
Error in load(file = "/home/ubuntu/myfile.RData") :
bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file ‘myfile.RData’ has magic number 'RDX3'
Use of save versions prior to 2 is deprecated
I've loaded similar RData files in the server before and it always worked fine. The same file is loaded without any problems in RStudio as I said, but somehow the server doesn't like it
Did you update R in your computer recently? If you did, from R 3.5.0, RData are saved using version 3 by default (RDX3). If you have an earlier version of R in your server, you probably need to save your data using the right version for your server (updating R in your server is another option). Please check the option version in the help of the save command to learn how to do that.

Resources