def to_df(self, variables=None, format='wide', sparse=True,
              sampling_rate=None, include_sparse=True, include_dense=True,
              **kwargs):
        ''' Merge columns into a single pandas DataFrame.

        Args:
            variables (list): Optional list of variable names to retain;
                if None, all variables are written out.
            format (str): Whether to return a DataFrame in 'wide' or 'long'
                format. In 'wide' format, each row is defined by a unique
                onset/duration, and each variable is in a separate column. In
                'long' format, each row is a unique combination of onset,
                duration, and variable name, and a single 'amplitude' column
                provides the value.
            sparse (bool): If True, variables will be kept in a sparse
                format provided they are all internally represented as such.
                If False, a dense matrix (i.e., uniform sampling rate for all
                events) will be exported. Will be ignored if at least one
                variable is dense.
            sampling_rate (float): If a dense matrix is written out, the
                sampling rate (in Hz) to use for downsampling. Defaults to the
                value currently set in the instance.
            kwargs: Optional keyword arguments to pass onto each Variable's
                to_df() call (e.g., condition, entities, and timing).
            include_sparse (bool): Whether or not to include sparse Variables.
            include_dense (bool): Whether or not to include dense Variables.

        Returns: A pandas DataFrame.
        '''

        if not include_sparse and not include_dense:
            raise ValueError("You can't exclude both dense and sparse "
                             "variables! That leaves nothing!")

        if variables is None:
            variables = list(self.variables.keys())

        if not include_sparse:
            variables = [v for v in variables if
                         isinstance(self.variables[v], DenseRunVariable)]

        if not include_dense:
            variables = [v for v in variables if not
                         isinstance(self.variables[v], DenseRunVariable)]

        if not variables:
            return None

        _vars = [self.variables[v] for v in variables]
        if sparse and all(isinstance(v, SimpleVariable) for v in _vars):
            variables = _vars

        else:
            sampling_rate = sampling_rate or self.sampling_rate

            # Make sure all variables have the same sampling rate
            variables = list(self.resample(sampling_rate, variables,
                                           force_dense=True,
                                           in_place=False).values())

        return super(BIDSRunVariableCollection, self).to_df(variables, format,
                                                            **kwargs)
Merge columns into a single pandas DataFrame.

        Args:
            variables (list): Optional list of variable names to retain;
                if None, all variables are written out.
            format (str): Whether to return a DataFrame in 'wide' or 'long'
                format. In 'wide' format, each row is defined by a unique
                onset/duration, and each variable is in a separate column. In
                'long' format, each row is a unique combination of onset,
                duration, and variable name, and a single 'amplitude' column
                provides the value.
            sparse (bool): If True, variables will be kept in a sparse
                format provided they are all internally represented as such.
                If False, a dense matrix (i.e., uniform sampling rate for all
                events) will be exported. Will be ignored if at least one
                variable is dense.
            sampling_rate (float): If a dense matrix is written out, the
                sampling rate (in Hz) to use for downsampling. Defaults to the
                value currently set in the instance.
            kwargs: Optional keyword arguments to pass onto each Variable's
                to_df() call (e.g., condition, entities, and timing).
            include_sparse (bool): Whether or not to include sparse Variables.
            include_dense (bool): Whether or not to include dense Variables.

        Returns: A pandas DataFrame.