If a team were to use a coding template given to them by another team, but modified the code to suit their robot, would that be allowed under R2 and G4?
Rule <G2> states that "Students must be prepared to demonstrate an active understanding of their Robot’s
construction and programming to judges or event staff. It also says that the rule "operates in tandem with the REC Foundation Student Centered Policy". Rule <G2> is reinforced by related language in rule <R2> and clause aiii of rule <G4>.
The Student-Centered Policy specifically addresses the scenario you've described, quoted in part below:
Teams that utilize example code or custom libraries from outside sources should use caution. The program used in the machine should represent the students’ design efforts and abilities. Blindly using code without understanding the code functionality is not consistent with the educational goals of this program. Students should be able to understand and explain the code used on their machines, and students should be able to demonstrate that they can program on a level equivalent to the code included on their machine.
To find the full text of this topic in the policy, visit the link above and search for the heading "Importance of Fundamentals".
Teams that cannot demonstrate an active understanding of their Robot's programming are likely in violation of rules <G2>, <G4> part aiii, and <R2>. Match Affecting or repeated violations of these rules will lead to Disqualification from the current Match, and can lead to the Team's removal from the event under rule <G1>.