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.

Thanks

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

Take an example here

data("cars")
names(cars)

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

attach(cars)

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.