Using writexl to export a dataframe containing real and complex numbers

I am trying to export a dataframe named "mat" (which has real and complex numbers) from R Studio to my desktop using the function write_xlsx() from the package writexl. The command does not throw any error and a file is also exported to my desktop but when I open the .xlsx file, there are no entries. It only has column numbers. Does writexl() not work with complex numbers? And if that is the case, is there an alternative way to export this dataframe to my computer?

write_xlsx(mat, col_names = TRUE,
           format_headers = TRUE,"/Users/Desktop/mat.xlsx")

This is not a reproducible example : you are having problem and you expect of us to check to which package this function belongs. And then to check its documentation.

And as for an alternative: a complex number is most often written as the sum of the real and the imaginary part. This could suggest a solution?

@HanOostdijk I was trying to create a reproducible example using the reprex package but when I try this example from Get help!, it throws an error message.

library(reprex)
(y <- 1:4)
mean(y)

As instructed in the reprex package help, I type reprex() in the console. It did return a result earlier on the clipboard but now when I type the above code, it returns this error while rendering reprex:

Error in parse(text = x, keep.source = TRUE) : 
  <text>:5:9: unexpected symbol
4: 
5: Warning message
           ^

I have used reprex for the first time and not sure what is going wrong. I updated the R studio version and all the installed packages but this issue remains. Any help would be greatly appreciated.

Hello @mohitarora ,

I do not know what went wrong at your site.

I use the software in the following way:
I select the lines that I want to include in the edit panel e.g.

(y <- 1:4)
mean(y)

With these lines select I click on Addins (see picture).
Depending on packages you have installed you see one or more sections.
In the REPREX section (it must be there if you have installed the package reprex) you choose Reprex selection . In the viewer panel the result is displayed. You can select its contents and copy it (in a post or response to a post) between two lines with three backticks (as you did in your last answer)

You can also use Render reprex... in the REPREX addin section.

Let us know if this works.

@HanOostdijk , I did what you suggested and it works now! Thanks - this has been really helpful.

This topic was automatically closed 21 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.