getComment = function(d) {
  comment = getHeader()
  comment = paste(comment,filenameComment(d), sep="\n")
  comment = paste(comment,sourceComment(d), sep="\n")
  comment = paste(comment,additionalVariables(d), sep="\n")
  comment = paste(comment,getFooter(), sep="\n")
  return(comment)
}

getHeader = function(no_of_hashes = 20) {
  comment_line = paste(rep("#", no_of_hashes), collapse="")
  header = paste(comment_line, "#Computerised marking",
    comment_line, sep="\n")
  return(header)
}

getFooter = function(no_of_hashes = 20) {
  comment_line = paste(rep("#", no_of_hashes), collapse="")
  footer = paste(comment_line, comment_line, sep="\n")
  return(footer)
}

filenameComment = function(d) {
  mark_filename = "#Is the filename correct?"
  if(d$has_correct_filename)
    comment = "#Yes"
  else {
    comment = paste("#No:", d$filename, "It should have been: ",
      d$correct_filename)
    comment = paste(comment, "Lose 10 marks", sep="\n")
  }
  mark_filename = paste(mark_filename, comment, sep="\n")
  
  return(mark_filename)
}

sourceComment = function(d) {
  mark_source = "#Can I load the file?"
  if(d$can_source)
    comment = "#Yes"
  else {
    comment = paste("#No:", d$source_error )
    comment = paste(comment, "#0 marks since I can't run your code", sep="\n")
  }
  mark_source = paste(mark_source, comment, sep="\n")

  return(mark_source)
}

additionalVariables = function(d) {
  mark_var = "#Does your file contain non-functions?"
  if(d$has_add_variables) {
    comment = "#Yes, Your file has the variables:"
    comment = paste(comment, paste(d$add_variables, collapse=" "))
    comment = paste(comment, "Lose 10 marks", sep="\n")
  } else {
    comment = "#No"
  }
  mark_var = paste(mark_var, comment, sep="\n")
  return(mark_var)
}
