import re


def naive_error_classifier(error_string):
    """Attempts to guess the cause of an error in R
    Parameters
    ----------
    error_string : string
                   error output

    Returns
    -------
    Likely error type (library, setwd, No such file) or None
    """
    if re.search('library\s*\(', error_string):
        return '(This is likely an error with a call to the \"library\" function. ' + \
               'Please ensure that you\'re not specifying a particular location for the package you\'re trying to load. ' + \
               'To try and automatically correct this error, select the automatic error fixing option in the Build Image form.)'

    if re.search('setwd\s*\(', error_string):
        return '(This is likely an error with a call to the \"setwd\" function. ' + \
               'Please ensure that you\'re not specifying an absolute path for your working directory. ' + \
               'To try and automatically correct this error, select the automatic error fixing option in the Build Image form.)'
    if (re.search('file\s*\(', error_string) or re.search('cannot open the connection', error_string)
            or re.search('No such file', error_string)):
        return '(This is likely an error importing data from a file. ' + \
               'Please ensure that you\'re specifying the correct path to your data, and that your data is ' + \
               'included in the file you uploaded. ' + \
               'To try and automatically correct this error, select the automatic error fixing option in the Build Image form.)'
    return ''