Error processing gps file in R script - r

Newbie R question: I have been trying to test the R script posted in FlowingData, but the script spit out the following error:
Error: XML content does not seem to be XML: 'NA'
I am running R on my windows box, with the .gpx files in the same directory as the script. Any help is appreciated.

Not sure if you ever found the answer to this or not, but the XML error relates to the fact that R does not know where your .gpx files are. While the FlowingData script indicates that the script will work if the .gpx files are in the same folder as your saved R script copy/pasted from FlowingData, that is not true. You must also set your working directory to this path as well, then R will see your .gpx files. If you FlowingData R script file and .gpx files are in: C:\Users\leon\Documents\R then add this line under the library(plotKML) line to set your working directory: setwd("C:\\Users\\leon\\Documents\\R")
Another word of note, make sure you only use the RunKeeper gpx files for a fairly small geographic area or the plotted data will be insanely small.

Related

How to get here() to work with R markdown/Quarto

Hoping for some help - I have been banging my head for a few hours and I can't find a solution. I am trying to optimise a workflow which involves sourcing a script from a Quarto file (I imagine this would be the same for an R markdown file). If I run the actual script using here() to load csv files, it works perfectly and sets the root directory as:
here() starts at /Users/Jobs/2023/project_x
Which is where the R project file is located.
But if I source that same script from within a Quarto file it sets the root directory to one up from the folder containing the .qmd file, and prevents the csv files from being able to be read:
here() starts at /Users/Jobs/2023/project_x/Analysis/code
The .qmd file is located at:
here() starts at /Users/Jobs/2023/project_x/Analysis/code/rmd
Is this expected behaviour and can I get around it?
Using:
here::set_here("/Users/Jobs/2023/project_x")
in a .qmd code chunk seems to work and keep all paths using here() intact in the source script, but I don't think it's ideal as I still need to specify an absolute path in the first instance.
Open to other suggestions...

Why do I keep getting an error when trying to import my file?

I'm trying to read csv file using R notebook and keep getting this error:
Error: 'Examples/data/starbucks.csv' does not exist in current
working directory ('C:/Users/c227466/Desktop')
I'm not sure what's going on!
This is the code I used:
starbucks <- read_csv("Examples/data/starbucks.csv")
starbucks
Your working directory is your desktop (which is not recommended). On your desktop, you should add a folder "Examples" and, in it, another folder "data" and your file there.

Unable to change directory in R Studio - problem with oneDrive

I am facing a problem while trying to change directory to read a csv in Rstudio.
When I type getwd() I get this as my directory:
C:/Users/giorg/OneDrive/Υπολογιστής/MSc_Data_Science_&_CI/Introduction to Statistical methods for Data Science/Coursework
So when I try to read my csv I get that error:
C:/Users/giorg/OneDrive/ÕðïëïãéóôÞò/MSc_Data_Science_&_CI/Introduction to Statistical methods for Data Science/Coursework/x.csv': No such file or directory
I tried to change through Global options > General but I still have oneDrive in my path
And when I try with setwd() I get :
setwd("C:/Users/giorg/OneDrive/Υπολογιστής/Giorgos")
Error in setwd("C:/Users/giorg/OneDrive/<U+03A5>p<U+03BF><U+03BB><U+03BF><U+03B3><U+03B9>st<U+03AE><U+03C2>/Giorgos")
cannot change working directory
Any suggestions about what should I do?
I had the same problem at some point. When I tried to change the directory I got the same error. In my case, the problem started when I changed the language of my computer. The file which I wanted to use as directory named in Greek language and after I turned my computer to English, R couldn't recognize it.
The problem solved when I renamed the file with English characters.

My R scripts perfectly work when running , but when I use the same scripts in R markdown get an error "does not exist in current working directory"

My R scripts perfectly work when running when in scripts file in R studio, but when I use the same scripts in R markdown get an error; file "does not exist in current working directory"
Both are in the same wd.
What may be the reason?.
Note: All my work do in google drive offline.
This is probably because R looks for files relative to the current working directory - by default Sys.getenv("HOME"), whereas knitr looks in the same directory as the Rmarkdown file.
The solution is to specify the correct full or relative path to files in the RMarkdown code.
This is what the new here R package was designed for. It always looks at the root of the R project directory (which is what "here" refers to). It doesn't matter if your Rmarkdown file is in a subdirectory.
library(here)
here("file_i_want.csv")
This will work the same regardless of if you use R scripts or Rmarkdown
More details here (pun intended):
https://github.com/jennybc/here_here

Read a .csv file with Sparklyr in R

I have couple of .csv files in C:\Users\USER_NAME\Documents which are more than 2 GB in size. I want to use Apache Spark to read the data out of them in R. I am using Microsoft R Open 3.3.1 with Spark 2.0.1.
I am stuck with reading the .csv files with the function spark_read_csv(...) defined in Sparklyr package. It is asking for a file path which starts with file://. I want to know the proper file path for my case starting with file:// and ends with the file name which are in .../Documents directory.
I had a similar problem. In my case it was necessary for the .csv file to be put into the hdfs file system before calling it with spark_read_csv.
I think you probably have a similar problem.
If your cluster is also running with hdfs you need to use:
hdfs dfs -put
Best,
Felix

Resources