writexl
writexl copied to clipboard
Is it possible to add a row_names parameter?
I'd like to be able to read in a data frame's row names. I see col_names, but it would also be helpful to have row_names.
Can't you just add add the row names to a regular column in your data frame?
mtcars$name = row.names(mtcars)
write_xlsx(mtcars, "mtcars.xlsx")
Can't you just add add the row names to a regular column in your data frame?
mtcars$name = row.names(mtcars) write_xlsx(mtcars, "mtcars.xlsx")
This wouldn't work for creating an xlsx with multiple named sheets ...
Hi, I had the same issue, It is very important for me to have the row names. the code you mentioned is working for me but in general, it is useful and easier to have the row_names = TRUE in function as there is col_names = TRUE....
Thanks :-)
I do not quite understand the importance :), but you could, of course write your own function.
Something like this when x is a data frame and not a list (for lists of data frames, alter this function):
write_xlsx_rownames <- function(
x,
path = tempfile(fileext= ".xlsx"),
col_names = TRUE,
row_names = TRUE,
format_headers = TRUE,
use_zip64 = FALSE
){
if (row_names == TRUE){
x <- data.frame(rowname = row.names(x), x)
}
write_xlsx(
x,
path = path,
col_names = col_names,
format_headers = format_headers,
use_zip64 = use_zip64
)
}
I have not tested it (I am writing on my mobile phone), but I guess you get the idea.
it is important cause I am working with gene sequencing data and rownames are gene names! :-) and this function is working thank you 👍