using attach/with vs pipes

Hi everyone,

A quick question if I may. when dealing with data when it's better to use attach and/or with rather than pipes.


Attach makes the variables contained in the data available by their names

Take an example here


First attach the data to make the variables available as R object(s)


Now call variables directly

head(Price, 2) ; head(Mileage, 2) ; head(Cylinder, 2)

When using pipe you will need to refer to the data frame containing your data

and it is best used with some supporting libraries (dplyr/tidyverse)

cars |> dplyr::select('Price') |> head(2)

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.