In the following examples, evaluate each problem using the criteria of a minimal reproducible example from [this StackOverflow post](https://stackoverflow.com/help/minimal-reproducible-example). 

Specifically, address the following things: 

1. Are the question and problem description complete?

2. Is the issue reproducible? Does it have a description of the problem, with code that reproduces the problem? What could improve it?

3. Is the example minimal? Does it include extra code or information that is not necessary?

4. Does the question describe any attempted solutions?


Then, using what you know about R and Python, try to debug the problem using the strategies in [the debugging chapter](https://srvanderplas.github.io/stat-computing-r-python/part-gen-prog/06-debugging.html). Once you are thoroughly stumped, or you believe you have solved the problem, compare your solutions to those given on StackOverflow using the link.

# Why Doesn't this R function work?

> I created the following function to append new strings on a vector of strings called "meals". However, when I use this function to append an string input into my "meals" vector, it does not work.

```
 add <- function(str) {
      meals <- append(meals, as.character(str))  
    }
```

[Link](https://stackoverflow.com/questions/39795961/why-doesnt-this-r-function-work?noredirect=1&lq=1) to original SO post. 



# Function not working R

> I've never programmed before and am trying to learn. I'm following that "coursera" course that I've seen other people post about — a course offered by Johns Hopkins on R programming.

> Anyway, this was supposed to be my first function. Yet, it doesn't work! But when I type out all the steps individually, it runs just fine... Can anyone tell me why?

```
pollutantmean <- function(directory, pollutant, id = 1:332){
    x<- list.files("/Users/mike******/Desktop/directory", full.names=TRUE)
    y<- lapply(x, read.csv)
    z<- do.call(rbind.data.frame, y[id])

    mean(z$pollutant, na.rm=TRUE)
}
pollutantmean(specdata,nitrate,1:10)
[1] NA
Warning message:
In mean.default(z$pollutant, na.rm = TRUE) :
  argument is not numeric or logical: returning NA

####

x<- list.files("/Users/mike******/Desktop/specdata",full.names=TRUE)
y<- lapply(x,read.csv)
z<- do.call(rbind.data.frame,y[1:10])
mean(z$nitrate,na.rm=TRUE)
[1] 0.7976266
```


[Link](https://stackoverflow.com/questions/24123224/function-not-working-r/24141502)



# Inexplicable error when trying to export my R notebook

> Getting this error from R Markdown when trying to export my .RMD

```
"Error in filter(Gastropods, Species == "Cellana") :  object 'Species' not found Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> filter"
```

> However, all my plots are coming out successfully. I can clearly see in the data that the species column is there and that Cellana is a species. No spelling errors or anything.

> My first 20 or so lines of code are below (between the ### symbols)


````{r echo=FALSE}
cat(paste(readLines("https://raw.githubusercontent.com/unl-statistics/stat850/refs/heads/main/homework/debugging_3.txt"), collapse = '\n'))
````

You can find this sample file [here](https://raw.githubusercontent.com/unl-statistics/stat850/refs/heads/main/homework/debugging_3.txt)


[Link](https://stackoverflow.com/questions/44193367/inexplicable-error-when-trying-to-export-my-r-notebook)


# Python if elif else statement

> I'm trying to create a program with python that calculate the cost for shipping.

> However, I can't run the program to where it works properly.

> What ever my total is the same amount comes out as $6 for US and $8 for Canada. I can't seem to get pass that.

> Example:

```
total = raw_input('What is the total amount for your online shopping?')
country = raw_input('Shipping within the US or Canada?')

if country == "US":
    if total <= "50":
        print "Shipping Costs $6.00"
    elif total <= "100":
            print "Shipping Costs $9.00"
    elif total <= "150":
            print "Shipping Costs $12.00"
    else:
        print "FREE"

if country == "Canada":
    if total <= "50":
        print "Shipping Costs $8.00"
    elif total <= "100":
        print "Shipping Costs $12.00"
    elif total <= "150":
        print "Shipping Costs $15.00"
    else:
        print "FREE"
```


[Link](https://stackoverflow.com/questions/19371643/python-if-elif-else-statement)
