0

I have a function custom_1 and when I use print(custom_1) R prints the returned data.frame but also some text at the bottom such as

The final values used for the model were mtry = 10 and ntree = 250

What i want to do is print the data.frame and the text but every time I try to write to a file only the dataframe gets printed.

This is the code i've been using.

write.csv(print(custom_1), file="results2.csv")
data princess
  • 1,130
  • 1
  • 23
  • 42
Walshe_d
  • 157
  • 2
  • 8
  • 1
    It would be easier to help you if you provided a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with some sample data and the desired output for that input. – MrFlick Jan 08 '18 at 19:04

1 Answers1

1

Use a sink. In your case:

sink("results2.csv") # open the connection
print(custom_1)
sink()               # close the connection

The sink function takes output that would ordinarily go to the console and writes it to the specified file.

data princess
  • 1,130
  • 1
  • 23
  • 42