Problem Knitting RMarkdown

Hello everyone I am pretty new to R and i am working on an RMarkdown file that keeps giving me the error shown in the picture. The code runs perfectly in the code chunks but will not knit. I changed the "inner_join" to merge and that fixed it but the next error was can't subset columns that dont exist. Could someone please help me fix these issues.

dailyActivity <- read_csv("FitabaseData_4.12.16-5.12.16/dailyActivity_merged.csv")
colnames(dailyActivity)
head(dailyActivity)
view(dailyActivity)

filter(dailyActivity, Calories >= 1, TotalSteps >= 1) %>%
  nrow()

dailyActivity_clean <- dailyActivity %>%
                        filter(Calories >= 1, TotalSteps >= 1) %>%
                        view()

dailyCalories <- read_csv("FitabaseData_4.12.16-5.12.16/dailyCalories_merged.csv")
colnames(dailyCalories)
head(dailyCalories)
view(dailyCalories)

dailyCalories_clean <- dailyCalories %>%
                       filter(Calories >= 1) %>%
                       view()
nrow(dailyCalories_clean)

dailySteps <- read_csv("FitabaseData_4.12.16-5.12.16/dailySteps_merged.csv")
colnames(dailySteps)
head(dailySteps)
view(dailySteps)

dailySteps_clean <- dailySteps %>%
                     filter(StepTotal >= 1) %>%
                     view()

dailyActivity_clean2 <- inner_join(dailyActivity_clean, dailyCalories_clean) %>%
                         view()

cleanDailyActivity <- inner_join(dailyActivity_clean2, dailySteps_clean) %>%
                       select(Id,ActivityDate, TotalSteps, Calories) %>%
                       view()

Here is the code above. Thanks in advance.

It would be useful if (in addition to the code) you provided the output showing the head() results for each of your data frames.

Note that RMarkdown starts with a clean session so it may be that you have something defined locally that isn't available to the RMarkdown session, resulting in the compile error.

You might also comment out that last line of code and see if it knits, just in an effort to isolate where the problem is.

These are the head for each of the dataframes. Thanks again

thank you so much for the reply. Since i couldnt add two images cos i am new i didnt but i just added the head to each frame in my reply.

This could be way off: I don't use view()... is that causing your issue? When I try it on a simply example such as:

mtfun <- mtcars %>% filter(mpg>=1) %>% View()
mtfun

It opens a table view window BUT mtfun is left as NULL.

And note the upper case View() instead of the lower case view() in your code?

mtfun <- mtcars %>% filter(mpg>=1) 
mtfun

stores the appropriate result in mtfun.

So I use the lower case view() in y code. I believe it is part of the dplyr library of functions. I run your example code and it run perfectly on my end using the tidyverse library.

Aah. view() is in tibble, works now for me too.

Back to your question... did you comment out the last line (I'm assuming that's where the issue is?) Could you break it into 2 steps and see if the first works? And make sure the columns are in intermediate the result? Something like:

cDA <- inner_join(dailyActivity_clean2, dailySteps_clean) 

cleanDailyActivity <- cDA %>% select(Id,ActivityDate, TotalSteps, 
   Calories) %>% view()

Maybe print out the head() of cDA here?

Alright lemme give that a try. To be honest i believe your advice to comment it out would be the best course of action, however i still want to know why this happened.

Yes, definitely! :grinning: Comment it out only in an effort to confirm that's what causing knit to fail. Then figure out why.

I FIGURED IT OUT!!!! So it turns out that in my RMarkdown I had added an nrow() before the view. Which means that the dataframe ended becoming a table of the nrow and not the real values. Such a learning experience. Thank you so much for the help. Is the anyway i can follow you or something so i can reach out when i have an issue and you have the time?

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.