18  Adding rows from another table

add_rows stacks another table underneath this one. Nothing is matched and no column is added; the rows just carry on where the first table stopped.

more <- data.frame(
  region = "North", product = "Sprocket", revenue = 400, cost = 120,
  stringsAsFactors = FALSE
)

sales |> add_rows(more) |> take(6)
region product revenue cost
West Widget 100 40
West Widget 200 50
West Gadget 300 100
West Gadget 150 50
East Widget 500 100
North Sprocket 400 120
more = pd.DataFrame({
    "region": ["North"], "product": ["Sprocket"],
    "revenue": [400], "cost": [120],
})

sales >> add_rows(more) >> take(6)
region product revenue cost
West Widget 100 40
West Widget 200 50
West Gadget 300 100
West Gadget 150 50
East Widget 500 100
North Sprocket 400 120

Both tables need the same columns. A column on one side only is refused rather than filled in with missing values, because a half-empty column that says nothing is how a mistake survives to the end of a pipeline.

collect(sales |> add_rows(data.frame(region = "North")))
Error:
! `add_rows` needs the other table by name: add_rows(more_sales)
try:
    collect(sales >> add_rows(pd.DataFrame({"region": ["North"]})))
except GodError as refusal:
    print(refusal)

illegal: `add_rows` needs both tables to have the same columns: this table has product, revenue, cost and `table` does not. Add what is missing, or drop it with `pick`
  |
2 |   then add_rows table
  |        ^^^^^^^^^^^^^^