0

I`m a BSc student just getting into R. I've done a bunch of things already (mainly for Psych statistics, plotting and other basic stuff). Yet when I try to knit a script I very often get error Messages. At first it was the same two errors repeatedly;

"trying to use CRAN without setting a mirror"

&

"cannot open the connection Calls: ... withCallingHandlders -> withVIsible -> eval -> eval -> read.table -> file".

Both of which I finally managed to track down (taken from here: Can't resolve error in .Rmd file <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> & Set default CRAN mirror permanent in R)

And now that I'm finally over the technical issues, I keep getting bogged down in fundamental errors. Like RStudio not recognising basic commands like gather() and %>%, even though I have set the work directory, installed all the packages and put them in the workspace library. And when that didn't work, I copy/pasted someone else's, with the exact same codes that work and it still won't let me knit it to .hmtl.

I can't even check my basic work on any level and I feel like there must be some fundamental issue I'm missing. I've spent several hours a day troubleshooting introductory assignments (and even downloaded it on a different computer) and I keep getting these error messages every time I write any form of code.

Edit: [Data/HW6.txt] is just a generic table from the teacher for homework 6.

dat_w <- read.table(file="data/HW6.txt", header=TRUE, sep=",") 

dat_l <- dat_w %>%
  gather(adi:kft, key=Test, value=Score) %>%
  arrange(Gruppe, Subj) 

To which I put the packages and the commands

library(tidyr) 
library(dplyr)  

But when I go to knit that, the problem I get is still:

Error in dat_w %>% gather(adi:kft, key = Test, value = Score) %>% arrange(Gruppe, :
  could not find function "%>%" 

Edit 2: search() results are:

[1] ".GlobalEnv"       "package:dplyr"     "package:tidyr"     "tools:rstudio"
[5] "package:stats"    "package:graphics"  "package:grDevices" "package:utils"
[9] "package:datasets" "package:methods"   "Autoloads"         "package:base"
r2evans
  • 141,215
  • 6
  • 77
  • 149
  • I've removed the [tag:rstudio] tag, this is about R, not the IDE. – r2evans Jan 27 '19 at 17:35
  • You seem to understand the premise of some of the errors, namely that `gather` and `%>%` require the use of `library(tidyr)` and `library(dplyr)`, respectively (or just `library(tidyverse)`, though I discourage that in many situations). However, it's rather difficult to speculate on exactly what to fix and how without seeing a minimal working example (MWE). Please provide a *small* r-markdown example the demonstrates the errors you are having. Refs: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Jan 27 '19 at 17:38
  • You likely want to make sure you have the `dplyr` package loaded if you're trying to use the `gather()` function and `%>%` operator. This can be done using `library(dplyr)`. If you need to install the package altogether, use `install.packages("dplyr")`. – Dale Kube Jan 27 '19 at 17:38
  • 1
    Could you paste the result of `search()`? – NelsonGon Jan 27 '19 at 17:39
  • It might be important to know the return of `search()` *from within the rmarkdown document*, not (just) on the interactive console. – r2evans Jan 27 '19 at 17:40
  • I hope this is what you mean, @r2evans. I created a new program. This is the direct text from the professor. > dat_w <- read.table(file="data/HW6.txt", header=TRUE, sep=",") > dat_l <- dat_w %>% gather(adi:kft, key=Test, value=Score) %>% + arrange(Gruppe, Subj) To which I put the packages and the >library(tidyr) > library(dplyr) commands and when I go to knit that, the problem I get is still: ## Error in dat_w %>% gather(adi:kft, key = Test, value = Score) %>% arrange(Gruppe, : could not find function "%>%" – Anton Ingi Jan 27 '19 at 18:03
  • Search() results are: [1] ".GlobalEnv" "package:dplyr" "package:tidyr" "tools:rstudio" [5] "package:stats" "package:graphics" "package:grDevices" "package:utils" [9] "package:datasets" "package:methods" "Autoloads" "package:base" > – Anton Ingi Jan 27 '19 at 18:09
  • Anton, as you can now see, adding significant outputs into a comment makes things very hard to read. More the point, often times comments are not read by others looking at your question (sometimes because comments can be hidden). Please take the relevant output and paste (well-formatted) into your question. – r2evans Jan 27 '19 at 18:22
  • Further, since we know nothing about the content of `data/HW6.txt`, we can still only guess at what is going on with the data. A minimal working example is something that can be entered into a fresh, new R session and not get errors like `file not found` or `object not found`. We don't have access to your data or your console. Since you're talking about knitting an r-markdown document, *please provide a sufficiently-complete r-markdown document in your question*. I'm not being difficult, I'm being thorough. (Your problem is otherwise completely unreproducible.) – r2evans Jan 27 '19 at 18:27
  • Thanks. I'm just new to all of this, and it's taking me a while to even find where the things are I'm supposed to copy. I've put it in the original post. – Anton Ingi Jan 27 '19 at 18:33
  • I'm just trying to help you in how to ask a question in a way that will help others help you. Are you calling `library(dplyr)` (etc) in the console and then knitting the document? *That is not enough.* The environment in which your document is knitted is not necessarily the same as the environment on your console. If you need a package in the document, then you need to call `library(...)` in the document. Bottom line, we ***still*** need a working example, such as a *minimal-but-complete* r-markdown document. – r2evans Jan 27 '19 at 18:43

0 Answers0