Use of .RDA files in R CRAN package 'extRemes' - r

I am using the CRAN package extRemes in R.
By the command extremes.gui() the extremes toolkit opens. Now, the thing I want to do is opening one of .RDA data files that is included in the package, for example PORTw.rda. Now following the steps described in the tutorial (can be found here) something goes wrong in reading the .RDA files.
I do the following:
In the toolkit go to 'File' and then click on 'Read Data'. Select the file 'PORTw.rda' in the folder 'data' under 'extRemes'.
Select in the follwing window under the heading File Type 'R source'. Keep the boxes Heading and Delimiter empty and save the file as PORTw.
When I press the OK button it gives the following error in R:
Error in source("C:/Users/jawissie/Downloads/Documents/R/win-library/2.15/extRemes/data/PORTw.rda") :
C:/Users/jawissie/Downloads/Documents/R/win-library/2.15/extRemes/data/PORTw.rda:4:3: unexpected input
3:
4: Ý9–
Also when I try to open one of the .RDA files from the extRemes package it shows unreadable content.
Does anybody know if I am doing something wrong or if the delivered .RDA files are not correct?
(The .dat files of the same package doesn't give any problem)

I was having the same problem. The html version of the tutorial provides a link to the original .r files at; http://www.isse.ucar.edu/extremevalues/data/index.html . Just follow the link to the PORTw.R file copy and past the URL into the Read Data dialogue box and the data will be read into the workspace as originally intended.

RDA files need to be loaded with 'load'. When you "read data" you are using 'read.table'.

Related

The system cannot find the file specified in Rmarkdown

I am doing my current project in RStudio Desktop. I am doing RMarkdown to later transfer. I am having some trouble getting an error of the system cannot find the file specified RMarkdown. At first, it says that the combined_databike was not found, but I literally did it in the same file already also you can see in the upper right all of the data frames which mention "combined_databike." This being said when I am trying to hit knit it gives me the error. Now the error says is at the tripdata_202006, which I cannot understand because I imported every file from tripdata_202006 to tripdata_202105 using the "import dataset."
I want to understand why is not working and how I bring a solution.
That's because the file you want to read is not in the folder where your project or in this case your rmarkdown file is.
As you can see in the file list of your console, in your directory you have 4 files, and you don't have the folder "Bike data" where the file 202006-divvy-tripdata.csv is located, according to the path that is in line 83 of your code.
Maybe to solve that, I think you have two options, the first one is to write the whole path to the folder location and then to the file. And the second option is to move the folder "Bike data" with the files you have in it, where your rmarkdown file is located.

How do I get R to work with spaces in a file path?

I believe a switch to OneDrive is causing some issues in various packages in R due to spaces being incorporated into the file path name. One shown below is the readxl package. Is there a way to get the package to read the spaces in the file path names? Or is it something other than the spaces that I might have overlooked?
Installation and the loading of the library work fine. However, when trying to import an excel file, it only works if I put the file in a location without spaces in the file path. I need the file to be in OneDrive so that it will be backed up.
install.packages("readxl")
library("readxl")
TRENDS_2020 <- read_excel("C:\\Users\\name03\\OneDrive - Specific Details Here (ABC)\\Backup_12_22_2020\\WQ_ALL_FINAL_WEBSITE_PIVOT_TRENDS_2020.xlsx")
I get the following error when running that:
Error in utils::unzip(zip_path, list = TRUE) :
zip file 'C:\Users\name03\OneDrive - Specific Details Here (ABC)\Backup_12_22_2020\TRENDS_2020.xlsx' cannot be opened
The following does work for the same file that I copy and pasted into my C drive:
TRENDS_2020 <-read_excel("C:\\TRENDS_2020.xlsx")
Zip {utils}
treated as if passed to system, if the filepaths contain spaces they must be quoted e.g. by shQuote.
Statistical Data Analysis ETH Zurich

Why doesn't the nops_scan function of the R package exams create zip file?

I am trying to run the tutorial for written exams in the exams package (http://www.r-exams.org/tutorials/exams2nops/). Everything works fine until I am about to process the scanned documents using the nops_scan function, which normally should create a zip file.
In the console it says "Creating ZIP file", but nothing happens after that. Last output:
> nops_scan(dir = "nops_scan")
Loading required namespace: png
Reading PNG files:nops_scan1.png: Trimming PNG, rotating PNG,
extracting information, done.nops_scan2.png: Trimming PNG, rotating
PNG, extracting information, done.
Creating ZIP file:
... and then nothing happens.
I have tried to run dir("nops_scan") and it confirms that no zip file has been generated and placed in this folder.
The files in the tutorial are png-files, so what the tutorials says about running pdftk and ImageMagick, should not apply. From the tutorial: "Note that if there were PDF files that need to be scanned, then the PDF toolkit pdftk and the function convert from ImageMagick need to be available outside of R on the command line."
Could the problem still be related to the above comment about pdftk or ImageMagick? (Which program is used to create the zip files?) I do not know how to make these programs "available outside of R", so instruction on this would be appreciated!
The base zip() function from the tools package is used, see ?zip. If you are on Windows maybe you need to install the Rtools? These are available from CRAN at https://CRAN.R-project.org/bin/windows/Rtools/.
PDFTk and ImageMagick are not involved in this case, they are only needed to convert PDF files to PNG which can then be processed in R. (And just in case anybody else is looking for this information: http://www.R-exams.org/tutorials/installation/ provides links to installation files for these applications.)

Output of saved .R files in r

I want to save my code in R. I did:
save(Data,file="Code_Data.R")
When I open the file in R again, the code looks like hieroglyphics.
How can I save the code in a way, that I can read the code in an editor or RStudio again?
save outputs a binary copy of the objects you tell it to save, not R code. Because you are naming this file with a ".R" extension, RStudio is blindly trying to open this binary file as R code, and you are seeing the results of that mess.
Technically, the R language doesn't care what the extension of the file is. As long as you know that the file contains, you can load it back in with the command load("Code_Data.R"). However, if you want to get RStudio to recognize that this is actually a file containing binary data and not R code, try saving the file with the canonical ".RData" extension:
save(Data, file="Code_Data.RData")
Using the ".RData" extension will also help you and other programmers who look at your code avoid this confusion in the future.

Error Reading Multiple Excel Sheets Using openxlsx package in R

I'm trying to load an Excel workbook with a large number of tabs into R, do some analysis, and then export the results back into Excel. I'm using the openxlsx package because of some of the features of that package that are not easily accessible using other packages (such as the ability to create "comments" in the output file, color code the tabs, and work with 64-bit R).
When I try to read in the workbooks, I sometimes get the following error message (or something similar):
Error in unzip(xlsxFile, exdir = xmlDir) :
cannot open file 'C:/Users/MENDEL~1/AppData/Local/Temp/RtmpIb3WOf/_excelXMLRead/xl/worksheets/sheet5.xml': Permission denied
This error message doesn't always show up - but sometimes it will appear and the program crashes.
Does anyone have any ideas how to fix this problem? I don't know why the program sometimes thinks it doesn't have permission to access the sheets.
Thank you in advance!
I can think of two possible scenarios for this error:
Scenario 1:
C:/Users/MENDEL~1/AppData/Local/ (This looks like you are trying to read a temporary file)
Solution:
If that is the case try moving the file to a different location like desktop and make sure that you update your working directory accordingly.
Scenario 2
C:/Users/MENDEL~1/AppData/Local/Temp/RtmpIb3WOf/_excelXMLRead/xl/worksheets/sheet5.xml' (Looks like there is some issue with Sheet5 which is of type .xml and the openxlsx does not allow you to read .xml)
Solution:
Check if there is some issue with the format or contents of sheet5 in the file that you are trying to read.
For additional information check CRAN Documentation

Resources