0

I am attempting to get a cartesian combination of 3 data frames in RStudio and then have that output sinked to a file. I used the crossing function to get the combinations and the sink function to have the output added into a file. The code works and provides the Cartesian product of the 3 data sets (verified in the environment tab), but the output only shows the first 10 lines of output. I have tried options(max.print=999999), to no avail. This is what it says after the first 10 lines: # … with 61,992,438 more rows. I am trying to have it show all rows so that all rows are coded to the file. I've looked around stack and haven't found any answers to this. My code (yes its very messy as of now) is attached below:

library(tidyr) # Loads in the crossing and expand functions
Q14fb=read.csv("q14fb.csv") # Reads in the data sets
Q13e=read.csv("Q13e.csv")
Q14e=read.csv("Q14e.csv")
sink(file = "Q3combooutput.txt", append = TRUE, split=TRUE) # Creates a file
x=data.frame(x=c(Q13e)) # Codes in the data
y=data.frame(y=c(Q14e))
z=data.frame(z=c(Q14fb))
result=crossing (x,y,z) # Provides all possible combinations of the data sets
result # Provides the output
sink(append=TRUE) # Adds the output to the file
Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

0

The problem

sink() will only print output from the R Console to the file. Since result was created by tidyr::crossing(), it is a tibble, and the default printing for tibbles are just the first 10 rows.

Some solutions

You can print all lines of a tibble by wrapping it in print(result, n = Inf). However, you are probably better of using some of the standard ways of exporting a file from R, such as write.csv() to export a CSV file.

jpiversen
  • 3,062
  • 1
  • 8
  • 12