Target feature in training set or not?
Whether you need two different data sets depends on the arguments needed in function you are using. Some model fitting functions need a formula and a data argument. Some functions need a xand a y argument. Sometimes you have both options.

For example a linear model (lm) takes a formula and a data argument. Since you can only enter 1 data frame in the data argument, your dependent and independent variables have to be in one and the same dataframe. This is the same as in your example with the gbm function.

However for example a random forest (randomForestpackage) takes the arguments x and y. Therefore, you can have two dataframes (one with y data, one with x data).

Conclusion: it always depends on the function and package that you are using and the only way to find out is to read in the documentation which of those two ways you should be using.