Export list to Excel file

Hello.

I'm trying to export a list to a xlsx file using export_list command in rio package.

I wrote this command

export_list(list1, "D:/lista.xlsx")

Then I got this error message:

Error in export_list(list1, "D:/lista.xlsx") : 'file' must have a %s placehold

Can you help me solving this problem using this command or another?

Have you looked at the documentation for the {rio} package? It's available here: https://cran.r-project.org/web/packages/rio/rio.pdf.

Is list1 you are using as the first argument in the call to export_list a list of data frames?

From the documentaiton for the second argument, which I think relates to the error message you provided:

"A character vector string containing a single file name with a %s wildcard place-
holder, or a vector of file paths for multiple files to be imported. If x elements
are named, these will be used in place of %s, otherwise numbers will be used;
all elements must be named for names to be used."

1 Like

Is list1 you are using as the first argument in the call to export_list a list of data frames ?

list1 is a list object in R and not a list of data frames.

@Equation

Then you probably should not use {rio}. From the documentation relating to the first argument: "A list of data frames to be written to files."

1 Like

@Equation do you have any other idea?

For writing excel files I use the openxlsx package. The function to doit is write.xlsx and then type the object name and the excel file name. If you are working with a project in RStudio you don't need to specify the target folder.

write.xlsx(x = df, file = "excel_file.xlsx")

1 Like

Thank you, @Sergio_Garcia_Mora

But when I read the package file, about write.xlsx it says:

write a data.frame or list of data.frames to an xlsx file

I don't want to export a list of dataframes but a object of the type list.

An xlsx file is meant to contain tabular data with associated metadata describing format, how your list object should be represented on this context? In other words, how your list should look on a spreadsheet?. Knowing this might make it easier for us to figure out how to help you.

@andresrcs

I'm trying to export a regression output. R considers this output as a list.

It is not possible to directly export the whole "content" of a regression to an excel file because it contains several types of objects and not all of them are directly representable in tabular format.

If what you want is to export a statistics summary table for the regression, that it is possible, but we would need a proper REPRoducible EXample (reprex) illustrating your issue, to give you any specific advice.

1 Like

@andresrcs I used sucessfully the solution preconized here:

Thank you very much for your help.

This could be a little misleading for others reading this topic since the solution you linked doesn't actually export the output of a regression to an xlsx file but only prints the console output to a txt file.

I'm just leaving this comment as a clarification for others, I'm glad you were able to find a satisfactory solution for your issue.

1 Like

You're right @andresrcs .

There are also these two possible solutions:

Creates presentation-ready tables summarizing data sets, regression models, and more

How to create a professional regression table in R (5 minutes)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.