def writecodefile(filename, code, language):
    """Create a python file and write the code to it."""
    if language == 'python':
        with open(filename + '.py', 'w') as pyfile:
            pyfile.write(code)
            pyfile.close()
    elif language == 'bash':
        with open(filename + '.sh', 'w') as bashfile:
            bashfile.write(code)
            bashfile.close()
    elif language == 'R' or 'r':
        with open(filename + '.R', 'w') as rfile:
            rfile.write(code)
            rfile.close()
    else:
        raise NotImplementedError('%s is unsupported.' % language)
