Importance of Variable Naming - Assignment 2

Today I tackled a function debugging exercise in R that taught me an important lesson about variable scope and naming consistency. I was given a vector of test data and a broken function to fix.


The Problem: The issue was inconsistent variable naming. While the function parameter was correctly named assignment2, inside the function body, the code referenced assignment (missing the "2") and someData (a completely different name). R couldn't find these variables because they simply didn't exist.


 What I Learned: This exercise reinforced how crucial attention to detail is in programming. A simple typo in a variable name can break an entire function, even when the logic is perfectly sound. It also highlighted the importance of understanding function scope in R - variables inside functions need to either be parameters, locally defined, or accessible from the global environment.




Comments

Popular posts from this blog

R Programming Journal - Omar Hamad

Assignment 6

Generic Functions in R