Code not working, could not find function. Maps package - r

This error has me completely stumped. This morning my code worked, this afternoon it does not.
I'm using the maps package to bring through the country code based on Longitude and Latitude coordinates within a data frame. The code I am using is: Latest[, COUNTRY := map.where(x = LONGITUDE, y = LATITUDE)]
This morning this worked fine, but now, this afternoon, I get the following error message:
Error in :=(COUNTRY, map.where(x = LONGITUDE, y = LATITUDE)) :
could not find function ":="
I had installed other map packages in a desperate bid to try and identify cases that retrieved an NA result using this code, that's the only change I made.
Since then I have:
Restarted RStudio
Restarted my computer
Deleted all new packages and restarted Rstudo
Deleted and reinstalled R itself including packages
Deleted RStudio and reinstalled with the same version
Restarted my computer again
No matter what I do it just resolutely gives the same meaningless, at least to me, error.
I'm getting desperate here folks, have a major project I need to get over the line and this error has ground me to a halt!

Related

TCGABiolinks: GDCprepare never terminates and crashes

I recently started using TCGAbiolinks to process some gene expression from the TCGA database. All I need to do is download the data into an R file, and there are many examples online. However, every time I try the example codes, it crashes my R workspace and sometimes my PC entirely.
Here's the code I'm using:
library(TCGAbiolinks)
queryLUAD <- GDCquery(project = "TCGA-LUAD",
data.category = "Transcriptome Profiling",
data.type = "Gene Expression Quantification",
sample.type = "Primary Tumor",
legacy = FALSE,
workflow.type = "HTSeq - FPKM-UQ"
)
GGDCdownload(queryLUAD)
LUADRNAseq <- GDCprepare(queryLUAD,
save = TRUE,
save.filename = "LUAD.R")
As you can see, it's very simple and (as far as I can tell, identical) to examples like this one.
When I run this code, it downloads fully (I've checked the folder with the files). Then, I run GDCprepare. The progress bar starts and goes to 100%. Then, the command never terminates eventually either RStudio or my machine crashes.
Here's the terminal output:
> GDCdownload(queryLUAD)
Downloading data for project TCGA-LUAD
Of the 533 files for download 533 already exist.
All samples have been already downloaded
> LUADRNAseq <- GDCprepare(queryLUAD,
+ save = TRUE,
+ save.filename = "LUAD.R")
|==============================================================================================|100% Completed after 13 s
Although it says completed, it never does. To solve this, I've tried reinstalling TCGAbiolinks, updating R to the latest version, and even running it on an entirely different machine (a Mac instead of Windows). I've tried other datasets ("LUSC") and got the exact same behavior. Nothing has solved the issue, and I haven't found this issue mentioned anywhere online.
I am sincerely grateful for any and all advice on why this is happening and how I can fix it.
Experienced exactly the same problem. Tried a variety of things, and noticed it doesn't crash when dataset has less than 100 samples or running with "summarizedExperiment = FALSE" for dataset less than 300 samples.
I am facing the same issue here. Looks like there is some kind of a memory leak happening because my RAM usage goes to 100%. I managed to "GDCprepare" 500 samples without crashing with ~64GB RAM but even after finishing, the memory is still occupied by the R session, even if I try garbage collection and removing everything in the environment.
I didn't have this issue with TCGAbiolinks around a year ago...

ggplot2 error: Error in default + theme : non-numeric argument to binary operator

I have been getting the error Error in default + theme : non-numeric argument to binary operator. I have been using R and teaching R for a long time but I can't find this problem. I have included a reproducible example that fails this way below:
library(tibble)
library(ggplot2)
brains <- as_tibble(brains)
brains <- brains[1:10, ]
brains
ggplot(brains, aes(x = BodyWt, y = BrainWt)) +
geom_point()
The error occurs when executing the ggplot() statement.
My hardware is an HP Laptop 15-ef0xxx. I am running Windows 10 Home version 2004. I am running RStudio community edition "Water Lily" and R version R x64** 4.0.2.
I know this is a simple error and it is driving me crazy.
So I finally solved this problem. On the github issue I had opened Hiroaki commented that "One possibility is that you might set a invalid default theme in your .Rprofile, but I'm not sure..." (see link to issue below).
I'm not sure if your R file is part of a project but mine is.
So I went back and deleted the theme_set() line in my R file, went in and double checked all my project options and selected the option "Disable .Rprofile execution on session start/resume" and "Quit child processes on exit". And then I restarted the R session and now everything works. Including on the default R editor console.
I'm not sure if all those steps are necessary but that seemed to do the trick for me! Hope it helps.
I thought this was an RStudio issue but it seems it's possibly a ggplot2 > problem. I have verified using two different datasets that the same >error comes up when I try using ggplot2 in RStudio or using the default R >console. I get the exact same error with code that's been working fine >but now suddenly won't. I have opened an issue on Github (ggplot2) with a >reprex. Might be worth checking there: >https://github.com/tidyverse/ggplot2/issues/4177
I know this is not an answer per se but I don't have enough reputation >points to add a comment to the previous answer but I thought linking to >the issue on Github might help.
I think you have numbers quoted somewhere and you are trying to perform mathematical operation on character values. Consider
x <- c("5","6")
y <- x/1
> y <- x/1
Error in x/1 : non-numeric argument to binary operator
Now try converting x to numeric and perform the same operation.
y <- as.numeric(x)/1
> y
[1] 5 6
So, you need to use as.numeric on your variable.
The following should resove this issue
ggplot(brains, aes(x = as.numeric(BodyWt), y = as.numeric(BrainWt)))

Download GPM-IMERG satellite images in R

I've been trying (a lot) to download NASA's GPM-IMERG satellite images with precipitation data from R. I'm doing the question in this forum and not in the GIS forum because I read that most r users are here. (FYI: Im running Windows 10 and r 3.6.3 in rstudio). So far I've tried the following:
Created an account at PMM-NASA (see here). Everything worked well.
Installed the gpm package from devtools::install_github("csaybar/gpm"), followed by
gpm_getaxel() (see here). I tried running the following code.
gpm_download(path = RutaDownloads,
user = "myuser#email.com",
password = "myuser#email.com",
dates = c('2017-01-01','2017-02-28'),
band = 3,
lonMin = 70,
lonMax = 75,
latMin = 34,
latMax = 38,
product = 'finalrun',
quiet = F,
n = 1)
However, it did not worked. The error shown in rstudio is the following.
'gdal_translate' not found Error in gdaltranslate_exist() : GDAL
should be declared as a system variable if you are using Windows
I haven't had any problems running gdal when working with multiple rasters/vectors in R (so far). Does anyone know if I have to install gdal in my PC apart from installing rgdal in r? If so, how can I do it and 'synchronize' it with R to be used with gpm package? I know there is a lot of information in google, however, I'd rather take the advice from anyone that has done this before, because in the past I did not have such a good experience working, for example, with GDAL and Python, and that is the main reason I started working my GIS codes in R.
I also tried with another alternative installing the remotes package and remotes::install_github("bastianmanz/GPM_rain") (See here). However, this uses the rhdf5 package, which is not available for my R version, and thus I installed the BiocManager and then BiocManager::install("rhdf5") (following the instructions from here). With GPM_rain there are two possible ways to download the images: (1) with wget i.e. system_download, but its not straightforward because it needs a list of the files to download, and (2) with rcurl_download using RCurl. This seemed easy to use. Nevertheless, the first problem is that I cannot specify lat/long for the image extent and, as in point 2, it did not work. I tried running the following code:
rcurl_download(product = "nrt",
nrt_type = "late",
start = 20170101,
end = 20170131,
userpwd = "myuser#email.com:myuser#email.com")
But the error says that rcurl_downloadfunction was not found. How to fix any of the above errors or have any other solutions, I would be really grateful if you could share your experience, specially for option 2, where I can set lat/long to download the data. Thanks in advance,
Jorge.
--------------------------------------------------------------------------------------------------------
EDIT:
Package gpm is "retired" according to its developer (see here).

ggmap mapdist() not working after running devtools::install_github('dkahle/ggmap')

I wonder if someone can help,
I randevtools::install_github('dkahle/ggmap') when trying to fix the issue of ggmap mapdist function repeating calculation for certain O-D pairs.
before running this the code mapdist('Manchester Deaf Institute', 'Birmingham O2 Academy 1', mode = 'driving') would return a result, however now after running devtools::install_github('dkahle/ggmap')
I just get the following error Error intmp[[c(1, 1)]] : subscript out of bounds
I am no where near the API limit for the day, and as this was working perfectly beforehand I am unsure why this is not working.
Does anyone have any suggestions?
thanks
Not really a solution but the only was I have been able to get past this is to uninstall and reinstall R.

Can't project data to robinson map with ggplot "no system list"

I am trying to plot some points on a map in R following instructions found here
http://rpsychologist.com/working-with-shapefiles-projections-and-world-maps-in-ggplot
When I get to the line where I use the rgdal:project function though I get an error message
places_robin_df <- project(cbind(places_df$LONGITUDE, places_df$LATITUDE), proj="+init=ESRI:54030")
Error in project(cbind(places_df$LONGITUDE, places_df$LATITUDE), proj = "+init=ESRI:54030") :
no system list, errno: 2
I find that changing the ESRI:54030 to random gibberish gives me the same error message which suggests to me that it can't find the ESRI:54030 information. What do I need to do to get things working?
Note I am running R in Ubuntu 14.04.
I ended up finding the following link that suggested that ESRI is case sensitive in Linux and should be lower-case.
http://lists.osgeo.org/pipermail/mapserver-users/2011-October/070334.html
changing the code to
places_robin_df <- project(cbind(places_df$LONGITUDE, places_df$LATITUDE), proj="+init=esri:54030")
fixes things

Resources