0% found this document useful (0 votes)
2 views5 pages

Debugging Functions in Udemy Coding Lectures

This document explains how to debug three types of errors in R coding on the Udemy platform: Logic, Syntax, and Structural errors. Logic errors occur when the solution does not match the problem requirements, Syntax errors arise from mistakes in code structure, and Structural errors relate to the organization of exercises. The document provides examples and guidance on how to identify and correct these errors using Udemy's feedback system and R Studio.

Uploaded by

manni dua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Debugging Functions in Udemy Coding Lectures

This document explains how to debug three types of errors in R coding on the Udemy platform: Logic, Syntax, and Structural errors. Logic errors occur when the solution does not match the problem requirements, Syntax errors arise from mistakes in code structure, and Structural errors relate to the organization of exercises. The document provides examples and guidance on how to identify and correct these errors using Udemy's feedback system and R Studio.

Uploaded by

manni dua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Debugging functions in Udemy Coding Lectures

There are three types of errors when we code in R Udemy System: Logic, Syntax and Structural
errors. In this file we will learn how we can debug the three. This document is valid for every
coding exercise, except the Functions coding exercise where we will create our own
functions.
Our example exercise will be:

Logic Errors:
- Logic errors are examples where the solution developed doesn’t match what is asked on the
question. This happens for a multitude of reasons and is completely part of the learning process.
- As an example, the exercise asks us for a vector with the elements 1,2,3,4 – imagine we would
provide this solution:

Copyright: Ivo Bernardo – R Programming Course


- In this case, there was clearly a problem with the definition of the last element that is 5 and not
4 – Udemy platform normally gives us a good error message in this case – after you hit “Check
Solution” this is the error message:

The solution states that our result[[1]] – meaning the first exercise (the 1 states the exercise
where we have the error) is not equal to what is expected. Let’s extend our exercise to two
questions:

- Now let’s correct our first exercise and make a Logic mistake on exercise 2:

Copyright: Ivo Bernardo – R Programming Course


- As you can see, on exercise 2 we are dividing the vector by 2, instead of multiplying by 2. But
now, our first exercise is correct. Let’s see the output:

- Note that our error now refers result[[2]] – which means that our exercise 2 had some kind of
trouble.

- Bottom line, with logic errors, you can guide yourself through Udemy feedback system and use
the part between [[]] to understand which exercise you are failing – the first exercise that you fail
will be the one in the output.

- The second part of the all.equal helps to guide you on the right solution – notice that this test
expects that the resulting vector on exercise 2 is c(2,4,6,8), hence, our vector multiplied by 2. You
can guide yourself using the second part of the all.equal function where you will have what is
expected from our exercise output.

Syntax Errors:

- Syntax errors are trickier. Udemy’s feedback is not perfect in providing good feedback when you
make a syntax mistake – particularly in the color syntax – sometimes if you go around the
function and make a syntax mistake adding something accidentally you will have a multitude of
errors in the platform, as an example – if we add an extra parenthesis on our vector function:

Copyright: Ivo Bernardo – R Programming Course


- Udemy will be able to point you to the problem – but the output is confusing:

- If you find it difficult to deal with the Udemy feedback system, just copy your code and paste it
in R Studio – and execute it:

- The output on the console:

- The red colored lines help a lot in guiding you to the error and debugging the function

Copyright: Ivo Bernardo – R Programming Course


Structural Errors:
- These are the crazier types of errors and are not related to R coding in general but the way that
exercises were structured. As an example, my exercises are based on a function that outputs a
list. The function definition:

- And the output and closing of the function:

- It’s important that your code is enclosed between these two blocks of code– this is the
function that produces the outputs that will be fed to the test so don’t change these lines.

- Let’s see an example of what happens when we delete the function definition (don’t worry, this
will be much clearer and will make a lot of sense when we get to the Functions section  ) – this
is the code we submit on Udemy, without the function definition:

- To avoid these types of errors don’t delete the last line of the function or the first function
definition. Only change the lines of code that have variables with 0’s assigned to them.

Again, thank you for enrolling in my course and if you have additional trouble, message me on LinkedIn
– Congratulations for having a go at the coding exercises – this is a super important part of the process!

Copyright: Ivo Bernardo – R Programming Course

You might also like