excel and pc stuck freeze and bugged when openning files writen with r - r

i am writing excel files with an R script that read existing file run some formulas on it and then adding some columns to the original file and writing it as new file, but when i am opening the files in excel , i sometime get freezes and excel stuck , or even without opening excel my computer freeze a bit (for example file explorer not responsive)
i tried using write.csv , openxlsx and the xlsx libarry all bugged my computer a bit
EDIT: my files are pretty small something like 800X20 without any formulas only tables of numbers and letters they take about 100 kb, but i tried some functions for big files like write.xlsx2 which didn't help , i just have no idea what can impact on it im adding columns like that :
orgData["codes"]<-codes
time=rep(NA,length(orgData$codes))
time[1]=totalTime
orgData["totalTime"]<-time
right now i am using write.xslx from the openxslsx library like this :
orgData=orgData[,c("c1","c2",.....)]
orgData=analayze(orgData,name)
name=(paste(gsub('.{3}$',"",name),"xlsx",sep=""))
write.xlsx(orgData,file = paste("Out.",name),row.names = FALSE )

Related

Writing .xlsx in R, importing into PowerBi error

I'm experiencing an odd error. I have a large dataframe in R (75000 rows, 97 columns) and I need to save it out and then import it into Power Bi.
At first I just did the simple:
library(tidyverse)
write_csv(Visits,"Visits.csv")
and while it seems to export and looks fine in excel, the csv itself is all messed up when I look at the contents in Power Bi. Here's an example of what I mean:
The 'phase.x' column should only have "follow-up" or "treatment" in that column. In excel, looks great:
but that exact same file gets screwed up in Power Bi:
I figured that being a 'comma separated variable' file, there must be some extra comma somewhere, and I saved it as an .xlsx instead.
So, while in excel, I saved that .csv as an .xlsx and it opened great in Power Bi!
Jump forward a moment and instead of write_csv() in R, I use write.xlsx(). But now I get this error:
If I simply go to that file, open it in excel, save it and hit close, that error goes away and it can load into Power Bi just fine. I figure it has something to do with this question on here.
Any ideas on what I might be screwing up as I save it out of R? Somehow I can fix it in R and not have to open and save it every time?
In power BI check that your source has ignore quoted line breaks enabled. I've found this is often an issue with .csv files in PowerBI.

Where i can read large xlsx files in R so my PC doesn't Freeze

Im making a program in an R script where i have to read a 45 MB excel file.
The problem is when i run a command like this:
CarActive<- read_xlsx("C:/Users/chorixs/Dropbox(Filess)/BRUU/Cartera_X234.xlsx", sheet = 1, skip = 1,)
This command actually works!! It loads the variable CarActive into my R enviroment.
But most of the time it makes my PC to crash or frezee really bad.
So i need another way to load these types of files into my R Studio enviroment.
I'm using the "readxl" package for R.
Is there any way to make these commands in another way, maybe in an online server, where i can just load the file and downlad it as a Data Frame?

How to fill an excel file using R, while in the excel file

I'm trying to access an R script via an Excel file. That is, while I'm still in the Excel file, I'd like to run an R script, that fills that same Excel file. The reason for this is that Excel is not computationally efficient enough.
Now I know that normally, you're not able to fill an Excel file via R script when the Excel file is opened. My question is, is there a way to work around this? For instance, by letting the R script close, fill and then open the Excel file I'm calling the script from?
Any help would be much appreciated

Exporting csv using excel into R

I hope someone can help me solve the problem I am currently facing with excel. I have been trying to export a csv file I wrote in Excel Ver 16 into R studio but it keeps giving the "incomplete final line found by readTableHeader on 'Book1.csv'" error. I have included the screen shot of the error and the files I had used for this. This doesnt seem to happen for the other data set I downloaded directly from Kaggle called "adult-test.csv" though.
I have tried everything from reinstalling R, R studio, Excel, I even resorted to using Google Sheets and it still doesn't work. If anyone knows what I am doing wrong please do help!
Image of my R studio code
Picture of the csv file I am failing to read
Hard to guess here.
Sometimes Excel saves csv files incorrectly - even though cells below your table are empty Excel saves them in the csv because maybe in the past, there was something written in there.
So, here is a suggestion
Maybe try to read the Excel file directly, not save it first as a csv. You can do that for example with read.xlsx() from the openxlsx package.
If that does not help, please open the csv file with a text editor (not with Excel again). You will then be able to see the actual problem and if necessary, post the text here (instead of the Excel screenshot)

Cannot open the file after writing xlsx file using R openxlsx package

At first, I tried to read and write xlsx files in R (while comparing the output between the xlsx and openxlsx packages).
I work on mac os.
It worked well to read xlsx files using the read.xlsx() from both packages.
However, when it comes to writing a new file, only the xlsx::write.xlsx() worked.
To be more exact, the openxlsx::write.xlsx() command gave no error, and an xlsx file was successfully saved, but when I tried to open the file using Numbers (by double clicking on the file in the folder), an error message popped up telling me the file cannot be opened.
I tried different data frames, but the results remained the same. To show an example, please refer to the following line which I took directly from R help page. It should work but does not work for me.
write.xlsx(iris, file = "writeXLSX1.xlsx", colNames = TRUE, borders = "columns")
Anyone tell me what the problem is? I tried to google for old threads but it seems no one is discussing this problem. I know in many similar threads people suggested changing packages, okay...before that, can you tell me what the limitations of openxlsx are?

Resources