In the above example creating the Learner explicitly is not absolutely necessary.
As a general rule, you have to generate the Learner yourself if you want
to change any defaults, e.g., setting hyperparameter values or altering the predict type.
Otherwise, train and many other functions also accept the class name of the learner and
call makeLearner internally with default settings.

Training a learner works the same way for every type of learning problem.
Below is a survival analysis example where a
Cox proportional hazards model is fitted to the lung
data set.
Note that we use the corresponding lung.task provided by mlr.
All available Tasks are listed in the Appendix.

Accessing learner models

Function train returns an object of class WrappedModel, which encapsulates
the fitted model, i.e., the output of the underlying R learning method. Additionally,
it contains some information about the Learner, the Task, the features and
observations used for training, and the training time.
A WrappedModel can subsequently be used to make a
prediction for new observations.

Further options and comments

By default, the whole data set in the Task is used for training.
The subset argument of train takes a logical or integer vector that indicates which
observations to use, for example if you want to split your data into a training and a test
set or if you want to fit separate models to different subgroups in the data.

Note, for later, that all standard resampling strategies are supported.
Therefore you usually do not have to subset the data yourself.

Moreover, if the learner supports this, you can specify observation weights
that reflect the relevance of observations in the training process.
Weights can be useful in many regards, for example to express the reliability of the training
observations, reduce the influence of outliers or, if the data were collected over a longer
time period, increase the influence of recent data.
In supervised classification weights can be used to incorporate misclassification costs or
account for class imbalance.

For example in the BreastCancer data set class benign is almost
twice as frequent as class malignant.
In order to grant both classes equal importance in training the classifier we can weight the
examples according to the inverse class frequencies in the data set as shown in the following
R code.

As another side remark for more advanced readers:
By varying the weights in the calls to train, you could also implement your own variant of
a general boosting type algorithm on arbitrary mlr base learners.

As you may recall, it is also possible to set observation weights when creating the
Task. As a general rule, you should specify them in make*Task if the weights
really "belong" to the task and always should be used.
Otherwise, pass them to train.
The weights in train take precedence over the weights in Task.