R-Studio freezes when trying to load data - r

I was trying to load the dataset from this file https://github.com/WinVector/zmPDSwR/blob/master/Custdata/custdata.tsv
and RStudio freezes and crashes every time. How can I tell if there is something particular with the datafile or RStudio is unable to handle it? How would I be able to get this data into R?

I will provide you with a possible alternative.
I always get a strange error whenever I try to do the online-data-pull, so what I do is, I download the dataset and keep it in my project folder and do my work with that.
As far as the dataset is concerned, it is the standard tsv format.
A code-snippet for your reference is:
mydata <- read.table("~path/dataset.tsv",sep="\t", header=TRUE)

Related

Error when trying to export data frame using write_xlsx

Been using R for around two years now and this is the first time i've encountered this issue. I have a data.frame with approx 31,000 rows and 400 cols and I want to export to an excel sheet using write_xlsx
When I try this I get the following error:
write_xlsx(data, "FILEPATH")
[ERROR][libxlsxwriter/packager.c:1142]: Error in writing member in the zipfile
[ERROR] workbook_close(): Zip ZIP_ERRNO error while creating xlsx file 'FILEPATH'. System error = No error
Error: Error in libxlsxwriter: 'Zip generic error ZIP_ERRNO while creating the xlsx file.'
I think this error started when I inadvertently tried to open an Excel file that R was writing before it had actually completed. I have shut down R and restarted and also re-installed the writexl package to no avail.
The data i'm attempting to export is approx 150mb. When I try to write a smaller file (1.5mb) this works but when I try to open the excel file it says it is locked for editing by R and can open be opened 'read only'.
I have exported much larger data than this in the past with no issues so cannot figure this out, any help appreciated.
What OS are you using and is it possible that you are running out of free space in the tmp directory? – jmcnamara yesterday
I think you've cracked it. I had returned to work on Monday, ran the script again and, sure enough, it worked first time. Only difference is I had deleted some content from the directory I was working in because I had got a disk full notice!
I don't know write_xlsx but I would suggest a simple alternative as the following:
library(rio)
library(xlsx)
export(data, "exportname.xlsx")
However in your code might you need to add the file name as the following:
library(writexl)
write_xlsx(data, "FILEPATH// file name.xlsx")
Might this source could be helpful: https://datatofish.com/export-dataframe-to-excel-in-r/

Unable to read SPSS file from working directory

I have created a folder that has my dataset and set it as my working directory in Rstudio.
The dataset is an SPSS file which I named "Stats in R", I downloaded the packages foreign and Hmisc and tried to run to the following command to get the dataset:
data = read.csv("Stats in R.csv", header = TRUE)
…but the console showed the following message:
Error in file.choose() : file choice cancelled.
The problem is, my dataset is in the working directory but whenever I try to open it, R shows me an empty folder. I run the dir() command and instead of getting the directory content in the console, I get the following message:
character(0).
I really don't know what's the problem, the SPSS dataset is saved as a SAV file. I tried other extensions as well like CSV but nothing worked. Any suggestions, please? I really need to sort out that issue soon. Thank you!
It seems like you have some issue with your working directory - it's either not where you think it is, or you don't have full permissions and something is blocking the R Studio interface from accessing it.
Since you want to get this resolved quickly, the approach I would try is importing the file using the entire file path instead of the working directory, and then you can troubleshoot your WD when you have time.
This should work:
df <- read.csv("C://Users//Mina//Folder//Subfolder//Stats in R.csv", header = TRUE)

"filename.rdata" file Exploring and Converting to CSV

I'm no R-programmer (because of the problem I started learning it), I'm using Python, In a forcasting task I got a dataset signalList.rdata of a pheomenen called partial discharge.
I tried some commands to load, open and view, Hardly got a glimps
my_data <- get(load('C:/Users/Zack-PC/Desktop/Study/Data Sets/pdCluster/signalList.Rdata'))
but, since i lack deep knowledge about R, I wanted to convert it into a csv file, or any type that I can deal with in python.
or, explore it and copy-paste manually.
so, i'm asking for any solution whether using R or Python or any tool to get what's in the .rdata file.
Have you managed to load the data successfully into your working environment?
If so, write.csv is the function you are looking for.
If not,
setwd("C:/Users/Zack-PC/Desktop/Study/Data Sets/pdCluster/")
signalList <- load("signalList.Rdata")
write.csv(signalList, "signalList.csv")
should do the trick.
If you would like to remove signalList from your working directory,
rm(signalList)
will accomplish this.
Note: changing your working directory isn't necessary, it just makes it easier to read in a comment I feel. You may also specify another path for saving your csv to within the second argument of write.csv.

Error in excel charts when overwrite data from R

I am trying to automate some of my tests in R to produce a static report in Excel. I have created a template in Excel which has a few charts and tables(sheet 1).
Now I run my R code to generate the data to fill in the same excel template file on Sheet 2.
I am using Openxlsx package to loadworkbook(excel template), next I overwrite data in sheet 2 by deleting the sheet and recreating it again with the new data so that the excel template has data for new test runs.
This runs without any error. But when I open my excel back the charts disappear with the !REF# error whereas as the tables are overwritten properly in the template(sheet1).
Has anyone come across such a scenario? The method I am using is a bit weird but can't think of any other alternative.
Thanks in advance!!
This definitely sounds weird. Something seems off, but I'm sorry I can't tell you what the issue may be. Anyway, I would say, just use R to generate the data and dump everything into Excel. Then, run some VBA in Excel to create the charts. I have no idea what your VBA skills are like, but I'm guessing it would be much easier to crate charts in Excel using VBA, rather than trying to do all of this with R.
Here are a few resources that you may find useful.
https://www.thespreadsheetguru.com/blog/2015/3/1/the-vba-coding-guide-for-excel-charts-graph
https://analysistabs.com/excel-vba/chart-examples-tutorials/
http://www.sthda.com/english/wiki/r-xlsx-package-a-quick-start-guide-to-manipulate-excel-files-in-r
Finally, you can learn a lot by recording Macros and hitting F8 to step-through the code to see how everything works.

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