  We compute the critical density of collapse for spherically symmetric
overdensities in a class of f(R) modified gravity models. For the first time we
evolve the Einstein, scalar field and non-linear fluid equations, making the
minimal simplifying assumptions that the metric potentials and scalar field
remain quasi-static throughout the collapse. Initially evolving a top hat
profile, we find that the density threshold for collapse depends significantly
on the initial conditions imposed, specifically the choice of size and shape.
By imposing `natural' initial conditions, we obtain a fitting function for the
spherical collapse delta_c as a function of collapse redshift, mass of the
overdensity and f_{R0}, the background scalar field value at z=0. By extending
delta_c into drifting and diffusing barrier within the context of excursion set
theory, we obtain a realistic mass function that might be used to confront this
class of scalar-tensor models with observations of dark matter halos. The
proposed analytic formula for the halo mass function was tested against Monte
Carlo random walks for a wide class of moving barriers and can therefore be
applied to other modified gravity theories.
