'Apply Merge methods
@param r: the S3Request
@param attr: dictionary of parameters for the method handler
@return: output object to send to the view'

def apply_method(self, r, **attr):

    output = dict()
    auth = current.auth
    system_roles = auth.get_system_roles()
    if (not auth.s3_has_role(system_roles.ADMIN)):
        r.unauthorized()
    if (r.method == 'deduplicate'):
        if (r.http in ('GET', 'POST')):
            if ('remove' in r.get_vars):
                remove = (r.get_vars['remove'].lower() in ('1', 'true'))
            else:
                remove = False
            if remove:
                output = self.unmark(r, **attr)
            elif self.record_id:
                if (r.component and (not r.component.multiple)):
                    if (r.http == 'POST'):
                        output = self.mark(r, **attr)
                    else:
                        output = self.duplicates(r, **attr)
                else:
                    output = self.mark(r, **attr)
            else:
                output = self.duplicates(r, **attr)
        elif (r.http == 'DELETE'):
            output = self.unmark(r, **attr)
        else:
            r.error(405, current.ERROR.BAD_METHOD)
    else:
        r.error(405, current.ERROR.BAD_METHOD)
    return output
