Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to add a row_names parameter? #44

Open
ENIAC-6 opened this issue Jan 29, 2020 · 5 comments
Open

Is it possible to add a row_names parameter? #44

ENIAC-6 opened this issue Jan 29, 2020 · 5 comments

Comments

@ENIAC-6
Copy link

ENIAC-6 commented Jan 29, 2020

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.

@jeroen
Copy link
Member

jeroen commented Jan 29, 2020

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")

@Jimaras08
Copy link

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 ...

@Elham-adabi
Copy link

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 :-)

@rdatasculptor
Copy link

rdatasculptor commented Jun 22, 2022

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.

@Elham-adabi
Copy link

it is important cause I am working with gene sequencing data and rownames are gene names! :-)
and this function is working thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants