Tag Archives: R

R-common errors and their possible causes — Notes

Directory)
Common Errors and their possible causes (self-use) GGplot class data manipulation and function class

Update on 2019.05.11
Common Errors and their possible causes (for personal use)
The following are all their actual process met, now collected, easy to learn to use, you have encountered other, I can also collect and update into here ~
Ps: Even if you understand the error message, you may not be able to find out which step is wrong, so don’t spray “the error message has explained blabla or other words”.
Ggplot class

    Q: ggplot2_Error: geom_point requires the following missing desire: y
    A: stat = “indentity” or “density”, Q: Error: Discrete value to continuous scale
    A: The X or Y axis may be set to discrete, while data is continuous, and vice versa. For example, scale_x_Continuous (blablabla) is set, but the X-axis data is C (” val1 “, “val2”,blabal2), which creates a conflict, so errorxlim Ylim and Coord_cartesian might have the same effect with graphs, but not the same. Coord_cartesian is a local zoom that does not change the dataset, while Xlim Ylim is a filter dataset that does change the dataset.

Data manipulation and function classes

    dat[datx > 5, c(1,9)] # only select column 1 and 9
    dat[datx > 5, 1:9] # select column 1 to 9. Although these two are different, the tibble of tidyverse bag has the property of data.frame, but it is not completely equal to data.frame:
    error:

angaus.tc5.lr01 < – GBm. step(Data =model.data, GBM. x = 3:14, GBM. y = 2, family = “Bernoulli”, Tree.com Plexity = 5, learning.rate = 0.01, Bag.Fraction = 0.5)

Error: Must subset columns with a valid subscript vector.
ℹ Logical subscripts Must match the size of the indexed input.
x input from size 1 but subscript model. The mask has size 18.
Run rlang::last_error() to see where the error occurred.

This means that the columns of model.data cannot be recognized. Since model.data is the tidyverse package read_delim, try it and add as.data.frame().

Installation and use of R language ggmap package

R language GGMap package installation and use
Ggmap is a map drawing package that calls the Google Maps API via the get_map function.
1 The first attempt went wrong
At the beginning, get_map was used to fetch the map data directly in R. However, an error occurred. The interface to display the function request refused our request (HTTP error code: 403).

library(ggmap)
map=get_map(location='San Fransico',maptype='roadmap',zoom=12)

URL:http://maps.googleapis.com/maps/api/staticmap?center=San+Fransico& zoom=12& size=640x640& scale=2& maptype=roadmap& language=en-EN& sensor=false
2 Baidu Discovery
From July 16, 2018, Google will limit the number of API requests, charge fees for exceeding the limit, and make it mandatory for all projects to use the official API Key. Without the API Key, the quality of the map may degrade or the map will not work. The API key must be associated with a credit card, and if the limit is exceeded, Google will start charging from the credit card. The search giant first offered users a $200 a month credit for free. Google slashed the number of free requests, from 25,000 per day to 28,000 per month, or about 1,000 per day, to a quarter of that. Google users who do not apply for a settlement account can only access the interface once a day.
3. Solving problems
So errors occur because of the lack of interface in the request URL key, to apply for a key in the Google maps developer platform:
https://developers.google.cn/maps/documentation/
We also found that we need to associate the credit card account, that is, the account that needs to be cleared by the Google map interface. After completing a series of applications, we found through the URL that to retrieve this function, we need to enable the staticmap interface. After enabling the interface, we got the KEY of the staticmap interface, but we found that the package we just downloaded directly in R could not add the KEY parameter to the URL. Later, it was found that someone on GitHub had updated the ggmap package. Then remove the ggmap package installed previously, install the latest ggmap package from GitHub, and directly enter the code in R to install:

if(!requireNamespace("devtools")) install.packages("devtools")
devtools::install_github("dkahle/ggmap", ref = "tidyup")
library(ggmap)
register_google(key=”your google map API key”)

Add the KEY parameter to register_google() and call the get_map() function to get the map data. If you get an error message that register_google is not register_google, you have not successfully installed the GGMap package from GitHub.
https://stackoverflow.com/questions/53275443/unable-to-use-register-google-in-r
When I call get_map(), I find an error prompting HTTP request to send REQUEST_DENIED. It was found on StackOverflow that Google map still needs to apply for Geocoding API interface. After applying for the interface, it should be ok to call get_map.
https://stackoverflow.com/questions/52565472/get-map-not-passing-the-api-key/52617929#52617929
Appendix:
1, ggmap packet address: https://github.com/dkahle/ggmap
2, methods other than Google maps, can also study the openstreetmap:
https://www.openstreetmap.org/user/jbelien/diary/44356

R load(xxx.Rdata) Error bad restore file magic number (file may be corrupted) — no data loaded


Error in load(file) :
bad restore file magic number (file may be able) — no data loaded
in addition: Warning message:
file ‘Deng.Rdata’ has magic number ‘RDX3’
Use of save versions prior to 2 is deprecated

my Rdata was saved with R3.6 and loaded with R3.4
This occurs when the R version used is greater than or equal to 3.5.0 version, and the R version used to read the file is less than 3.5.0

It should be the R version mismatch
Solution: Add version= when saving Rdata and specify the R version at read time

Analysis of R language error replacement has length zero problem

I encountered this problem before when I was doing a for loop, where the second layer of the loop is , ncol=3, so here the loop is going to be for(j in 1:2) and then the assignment matrix is the following error.

After
, it was found on the Internet that the error was caused by improper alignment of array or matrix or out-of-bounds subscripts. After checking the code, it was found that there was indeed a small error, that is, for(j in 1:ncol-1) is equivalent to for(j in 0:1). Obviously, an error will be reported when assigning the value. for(j in 1: ncol-1)) correct.

To solve the problem of loading rjava in installation of xlsx

[run target]
import XLSX file,
install. Packages (” rJava “)
install. Packages (” xlsxjars “)
install. Packages (” XLSXX “)
install

[error prompt]

library (XLSX) Error: package or namespace load failed for ‘XLSX:
loadNamespace counting’ rJava ‘in his (). When the onLoad fails, the detailed content:
call: inDL (x, as the logical (local), as the logical (now),…).
error: unable to load Shared object “d:/Program Files/R/R – 3.5.0/library/rJava/libs/x64/rJava DLL: ‘
LoadLibrary failure: % 1 is not a valid Win32 application.

solution 】 【 1, Java on the website to download the Windows version of the Java software

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

download download time attention to agree with statement after good Java installation
note:
if R is 64-bit, the installed Java must also be 64-bit and placed in C:\Program Files…
if you install C:\Program Files (x86), the system will continue to report the following error

2, download the Java, and install it, Under CMD, type
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_171
Path=C:\Program Files\Java\jdk1.8.0_171\bin
you can also manually set


3, finally re-run
library(rJava)
library(xlsxjars)
library(XLSX)
XLSX package imported successfully

Error: package or namespace load failed for ‘rJava’:


library(“rJava”) Error: package or namespace load failed for ‘rJava’ : loadNamespace() calculate ‘rJava’. OnLoad failed, call: inDL(x, as. Logical (local), as. Logical (now)… Error: unable to load Shared object ‘C:/Users/DELL/Documents/R/win – 3.4/library/rJava/libs/x64/rJava DLL’ : LoadLibrary failure: can’t find the specified module.

Could you tell me how to deal with this problem in R language?

Error in compiling rmarkdown to PDF file` xxx.sty ‘ not found.

as: https://github.com/rstudio/rmarkdown/issues/39

error message

LaTeX Error: File 'framed.sty' not found.
LaTeX Error: File 'titling.sty' not found.

solution

method 1

USES Tex’s TLMGR package to manage the installation of the missing.sty file

tlmgr install framed

method 2

on my system, TLMGR install: package already present: framed but still reported an error, the following method successfully installed

yum install missing file

yum -y install texlive-framed
yum -y install texlive-titling

R:Error : .onLoad failed in loadNamespace() for ‘rJava’, details: call: dyn.load(file, DLLpa

R: unable to load the Shared object object ‘/ usr/lib64/R/library/rJava/libs/rJava. So

problem description:

when installing mailR package on R today, this error occurred

. After searching and finding, I tried to install a wave of rJava, but failed. The following error occurred:
can be found through this prompt message: R wants us to make sure that the JAVA in our environment is installed correctly (JAVA has been installed correctly in my environment)
if in doubt, use the Root account to run R CMD javareconf
then I run the R CMD javareconf

you can see the prompt message at the bottom: done.
after seeing this, I went into the R environment again, reinstalled the mailR package, and finally succeeded.

“Pandoc document conversion failed with error 1033” error message appears in rstudio knit

recently followed a course of data mining and machine learning in R language. While knitting to HTML, Rstudio was often buggy with

even when it was done more than one time

pandoc document conversion failed with error 1033

in the mind of mystery Debug, start trying Restart R, Restart RStudio, clear cache and other operations. Over time, however, none of these methods worked, and I had a vague feeling that a cache file conflict was causing the bug, but none of them worked.

there is no resistance in the browser search around the bug information, suddenly a brainwave:
Modify the file name of the.rmd file that needs to be converted

sure enough, this time there is no conflict, mystery debug success.