How to add excel sheet cell comments in R - r

I am currently cleaning survey data in R. The output will be an excel sheet. I am currently using this comment code to have comments appear in the top row of the excel sheet to explain variable names. An example of this code is: comment(ExitClean$Q1a_1)<-c("name"). While the code runs, it does not consistently create comments in the final excel sheet output. Is there a more updated package or code to use to ensure that these comments appear in the output?

Related

I want to create Box plot using R code programming and the output

I want to create box plot using below excel sheet by importing to R. I want the output and R code as well
excel sheet
I didn't try anything

Is there a R function to add data from a df and append it to a sheet in excel

I have a R code that uses joins from various tables and finally have an output dataframe. I need this to be appended to a new worksheet in excel file that already has three sheets in it. I am on a mac and however I try the library(rjava) that is required for library(xlsx) wont load. Is there any other library (that doesnt need java) that I can use for this?
Edit to add: the existing excel sheet has graphs and charts in it

Conditional Formatting in Pivot with openxlsx?

I have an Excel with several sheets, two of which contain pivot tables based on data from other sheets ("data sheets"). Using the openxlsx package, I'm loading the Excel into R and first removing the data sheets and then creating them again with new data. This works well and the pivots update accordingly.
However, if I apply conditional formatting to the pivots and perform the above process, then I obtain an error message when opening the new updated file (We found a problem with some content in [file]. Do you want us to try to recover as much as we can? [...]). After having done the repair, I get the message:
Repaired Records: Conditional formatting from /xl/pivotTables/pivotTable1.xml part (PivotTable view)
The conditional formatting has been removed after the repair. I have found this page which might be of use to me, but I haven't got their possible solutions to work:
https://github.com/awalker89/openxlsx/issues/387
I have also tried to construct a minimal Excel reproducing this behavior, but while the minimal Excel I produce yields the We found a problem... error, it does keep the conditional formatting once repaired.
Any ideas? Thanks in advance!

Exporting dataframe from R to Excel with styles and formatting

I would like to export a large table (similar to that shown in the image below) to Excel with parts of the string highlighted in few of the columns.
At present I am displaying the table columns using datatable employing rowCallback function to highlight the sub string. Then to export the table to Excel, I am manually copying the rows from the displayed datatable to an Excel worksheet.
I could not accomplish this particular challenge using openxlsx or other libraries.
Please advice on how to overcome this challenge!

Fetch data from an open excel sheet into R?

I am wondering is it possible to read an excel file that is currently open, and capture things you manually test into R?
I have an excel file opened (in Windows). In my excel, I have connected to a SSAS cube. And I do some manipulations using PivotTable Fields (like changing columns, rows, and filters) to understand the data. I would like to import some of the results I see in excel into R to create a report. (I mean without manually copy/paste the results into R or saving excel sheets to read them later). Is this a possible thing to do in R?
UPDATE
I was able to find an answer. Thanks to awesome package created by Andri Signorell.
library(DescTools)
fxls<-GetCurrXL()
tttt<-XLGetRange(header=TRUE)
I was able to find an answer. Thanks to awesome package created by Andri Signorell.
library(DescTools)
fxls<-GetCurrXL()
tttt<-XLGetRange(header=TRUE)
Copy the values you are interested in (in a single spread sheet at a time) to clipboard.
Then
dat = read.table('clipboard', header = TRUE, sep = "\t")
You can save the final excel spreadsheet as a csv file (comma separated).
Then use read.csv("filename") in R and go from there. Alternatively, you can use read.table("filename",sep=",") which is the more general version of read.csv(). For tab separated files, use sep="\t" and so forth.
I will assume this blog post will be useful: http://www.r-bloggers.com/a-million-ways-to-connect-r-and-excel/
In the R console, you can type
?read.table
for more information on the arguments and uses of this function. You can just repeat the same call in R after Excel sheet changes have been saved.

Resources