The system cannot find the file specified in Rmarkdown - r

I am doing my current project in RStudio Desktop. I am doing RMarkdown to later transfer. I am having some trouble getting an error of the system cannot find the file specified RMarkdown. At first, it says that the combined_databike was not found, but I literally did it in the same file already also you can see in the upper right all of the data frames which mention "combined_databike." This being said when I am trying to hit knit it gives me the error. Now the error says is at the tripdata_202006, which I cannot understand because I imported every file from tripdata_202006 to tripdata_202105 using the "import dataset."
I want to understand why is not working and how I bring a solution.

That's because the file you want to read is not in the folder where your project or in this case your rmarkdown file is.
As you can see in the file list of your console, in your directory you have 4 files, and you don't have the folder "Bike data" where the file 202006-divvy-tripdata.csv is located, according to the path that is in line 83 of your code.
Maybe to solve that, I think you have two options, the first one is to write the whole path to the folder location and then to the file. And the second option is to move the folder "Bike data" with the files you have in it, where your rmarkdown file is located.

Related

"The system cannot find the file specified whenever I knit"

Whenever I knit to a PDF in RStudio, the error "The system cannot find the file specified."
Here is the code that I'm using:
##importing data
library(readr)
Quiz1data_2 <- read_csv("C:/Users/erinp/Downloads/Quiz1data-2.csv")
I have restarted RStudio multiple times and I have copied and pasted the exact link that my file is saved to and it's still not working.
What am I not seeing or what am I not thinking?
Some suggestions/questions:
Without knitting, when you run the line reading in the csv, does it work?
Also, are you sure that the error is referring to the data csv? Could it be referring to the (I'm assuming) markdown file you are writing your code in? Have you moved that file since you started working in it?
Are you able to knit other documents to pdf? You need MiKTeX on a windows machine. Does knitting to html work?
I've found R to be a little tricky reading in files. I usually use the base function like this:go to the environment tab>import dataset>from text(base)> (select the file you want, hit open)>(select settings so that the dataframe preview looks right>import. Code that does this will run in the console, and I copy it into my markdown file so that every time it knits, it replicates that successful process.
I figured it out. It's because I forgot to assign a value to an object so it wouldn't knit into a PDF. I made a comment earlier, but it's small so I thought I would add this to the answer section.

Why is RStudio telling me that my file doesn't exist? I'm looking directly at it

I'm on RStudio, just wanting to read a csv file:
newdata <- read_csv("Nameofdata.csv",
col_names = TRUE)
But it keeps telling me that the file doesn't exist. It does exist. I'm staring DIRECTLY at it, underneath the file path that RStudio insists is wrong. I can open it in another tab, I can open in in excel, it's EXACTLY where RStudio says it's not existing. Please help.
Looking very closely at your screen shot, commenters are suggesting that you have an extra space at the beginning of your file name.
Also, I see that the working directory appears to be correct (the error message lists it as C:/users/mdavi/Desktop/School/Research/Sc, which appears to match what is listed in the Files pane
A couple of strategies for trouble-shooting file-locating problems:
use getwd() and list.files() to confirm your working directory and what files R can see from there (you can read this introduction to get more background on working directories):
use file.choose() to select a file interactively; it's generally a bad idea to use this in production code, as it will add an interactive step when you usually want to be able to run all of your code start to finish without needing manual steps, but it's quite useful for debugging.
If you wanted R to list files that approximately matched your specified filename, you could use
L <- list.files(pattern="*.csv")
agrep("myfile.csv", L, value=TRUE)
You need to set your working directly correctly, either via setwd("~/Desktop/School/Research/SC") in the R Console (that's what I think I see in your screenshot: ~ stands for your home directory, i.e "Users/Whoever") or via Session > Set Working Directory > To File Pane in the RStudio menus.
You can read a variety of Stack Overflow questions about setting the working directory for more complete context ... web searching on "R 'working directory'" might help too.

What is the right way to show up images at R Markdown?

I am doing an html document from R Markdown (RStudio) and I think I am following the right instructions to show it up. I read the R's Bookdown (https://bookdown.org/yihui/rmarkdown) and there says this is the way, or at least this is what I get from it. I am using this only script line to make the image calling:
![Hadley Wickham](Macintosh HD/Usuarios/ivanmendivelso/Dropbox/Escuela/IntroR Vids/HW.jpeg).
When knitting I get this error message: "File Macintosh HD/Usuarios/ivanmendivelso/Dropbox/Escuela/IntroR Vids/HW.jpeg not found in resource path
Error: pandoc document conversion failed with error 99
Execution halted".
Does anybody know what am I doing wrong? Why I can not see images in my documents?
Thanks in advance.
It looks like your path is not correct.
If the image can be moved, put it in the same directory as your .Rmd file. If you can't move it to the file directory and if you don't speak UNIX, you can get the path by:
Finding the file with the finder
Right click on it
hold the option key on your keyboard and you will see the menu change from Copy "HW.jpg" to say Copy "HW.jpeg" as pathname
Paste that path into your code.
When you have file spaces in your file path you need to put single quotes around to make them strings
![Hadley Wickham](‘Macintosh HD’/Usuarios/ivanmendivelso/Dropbox/Escuela/‘IntroR Vids’/HW.jpeg)
What about this below
![Hadley Wickham](/Macintosh HD/Usuarios/ivanmendivelso/Dropbox/Escuela/IntroR Vids/HW.jpeg).
notice the / at the begining of the file path. on Mac the very first / is meaning from the root of your hard drive

How can I avoid hardcoding a file path?

I am using RStudio to knit an .Rnw file to .pdf. This .Rnw file is stored in directory that is under git version control. This directory also contains a .RProj file for the project.
I collaborate with colleagues who don't know the first thing about .Rnw files and git. These colleagues want to open a Word file and track change their hearts out. So I give the people what they want.
Everyone needs access, so storing the Word file on a cloud service like Box makes sense. In the past I created a subfolder in my repo that I shared—keeping everything within the root directory—but this time around I needed to store the file in a shared folder that someone else created. So my solution was to copy the Word file from this shared directory to my repository.
Technical Approach
I don't know how to make this a reproducible problem, but hopefully you will give me some latitude since I'm trying to make my work fully reproducible ;)
Let's say that my .Rnw file is stored in repoRoot/subfolder. Since knitr changes the working directory to subfolder where this .Rnw file is located, the first chunk sets the root.dir one level up at the project root.
<<knitr, include=FALSE>>=
library(knitr)
opts_knit$set(root.dir=normalizePath('../')) # go up 1 level
#
The next chunk copies the Word file from the shared folder to my git repo and runs the analysis file. The shared directory path is hard coded to my machine, which is the problem I'm writing for your help solving.
file.copy(from='/Users/ericpgreen/Box Sync/Project/Paper/draft.docx',
to='subfolder/draft.docx', # my repo
overwrite=TRUE)
source(scripts/analysis.R) # generates objects we reference in the .docx file
After adding \begin{document}, I include a chunk where I convert the .docx file to .txt and then rename it to .Rnw.
# convert docx to txt
system("textutil -convert txt 'subfolder/draft.docx'")
# rename txt to .Rnw
file.rename('subfolder/draft.txt',
'subfolder/draft.Rnw')
The next child chunk calls this .Rnw file that contains the text of the Word file with references to R objects included through \Sexpr{}:
<<include-draft, child='draft.Rnw', include=FALSE>>=
#
This works just fine for me. Whenever I knit the .Rnw file it grabs the latest version of the .docx file that my colleagues have edited (complete with track changes and comments) and, in a later step not shown here, returns the .pdf file to the shared folder.
Problem to Solve
This setup meets almost every need for me, except that the initial file.copy() command is hard coded to my machine. So if someone in my group clones my repo (e.g., research assistants who DO use version control), it won't run out of the box. Is there a workaround to hard coding in this type of case?
Ultimately you won’t get around hard-coding paths that are outside your control, such as paths to network shares. What you can and should avoid is hard-coding these paths in your documents.
Instead, relegate them to configuration files and/or environment variables (which, again, will be controlle by configuration files, to with .bashrc and similar). The simplest approach is then to use
network_share_path = Sys.getenv('NETWORK_SHARE_PATH',
stop('no network share path configured'))
file.copy(from = network_share_path, to = 'subfolder/draft.docx', overwrite = TRUE)

Use of .RDA files in R CRAN package 'extRemes'

I am using the CRAN package extRemes in R.
By the command extremes.gui() the extremes toolkit opens. Now, the thing I want to do is opening one of .RDA data files that is included in the package, for example PORTw.rda. Now following the steps described in the tutorial (can be found here) something goes wrong in reading the .RDA files.
I do the following:
In the toolkit go to 'File' and then click on 'Read Data'. Select the file 'PORTw.rda' in the folder 'data' under 'extRemes'.
Select in the follwing window under the heading File Type 'R source'. Keep the boxes Heading and Delimiter empty and save the file as PORTw.
When I press the OK button it gives the following error in R:
Error in source("C:/Users/jawissie/Downloads/Documents/R/win-library/2.15/extRemes/data/PORTw.rda") :
C:/Users/jawissie/Downloads/Documents/R/win-library/2.15/extRemes/data/PORTw.rda:4:3: unexpected input
3:
4: Ý9–
Also when I try to open one of the .RDA files from the extRemes package it shows unreadable content.
Does anybody know if I am doing something wrong or if the delivered .RDA files are not correct?
(The .dat files of the same package doesn't give any problem)
I was having the same problem. The html version of the tutorial provides a link to the original .r files at; http://www.isse.ucar.edu/extremevalues/data/index.html . Just follow the link to the PORTw.R file copy and past the URL into the Read Data dialogue box and the data will be read into the workspace as originally intended.
RDA files need to be loaded with 'load'. When you "read data" you are using 'read.table'.

Resources