easystats/parameters

How can I convert the results in the console to csv files?

yohei-h opened this issue · 6 comments

How can I save the results displayed in the console as CSV files?
I would like to use the console results as it is for writing papers.
The following is an example.

library(tidyverse)
library(parameters)

model <- lm(Sepal.Length ~ . * ., data = iris) 

model %>%
    select_parameters() %>%
    parameters() %>% 
    summary() 

I tried write.csv(), but it did not work well: all the columns including SE and df_error were output, and the digits were not the same as the results in the console.

model %>%
    select_parameters() %>%
    parameters() %>% 
    summary() %>% 
    write.csv('~/Downloads/sample.csv')

I would aprreciate it if someone could tell me how to deal with it.

Use the format() function before writing the CSV

Thank you very much, @bwiernik.
format() looks nice, but summary() and print(select = )did not work well:

model %>%
    select_parameters() %>%
    parameters() %>% 
    format() %>% 
    write.csv('~/downloads/sample2.csv')

model %>%
    select_parameters() %>%
    parameters() %>% 
    summary() %>%  # summary() added
    format() %>% 
    write.csv('~/downloads/sample3.csv')

model %>%
    select_parameters() %>%
    parameters() %>% 
    print(select = '{Estimate} | {ci}') %>%  # select added
    format() %>% 
    write.csv('~/downloads/sample4.csv')

I would appreciate it if you could tell me another solution if any.

When you run parameters() and print() it, the intermediate function used to format the printing is format().

If you want to write the console output to CSV, go from parameters() to format()

Sure. I understand that the results of summary() and print(select =) are difficult to output as it is in the console.
Thank you very much for your quick reply.

I'm not sure CSV is a useful file format for formatted text output. If you're interested in copy-pasting tables into word, use print_html() and copy/paste. Or use packages like model_summary() and alike.

Thank you very much for your kind advice, @strengejacke.
Actually, I wanted to convert the results to CSV and do fine-tuning with Excel. I tried print_html() and found that print_html() followed by write.csv() looks quite good! Thank you again.