Tag Archives: Learning notes

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().

Solve the problem of syntax error: unexpected end of file or syntax error near unexpected token ` fi ‘error

When editing a file on Linux server, it would be troublesome to edit it directly in Linux environment. The format of large paste is messy, and we have to adjust it line by line, so we will choose to edit the file in our Linux environment with editor. I use NodePad++, You can refer to this blog to learn how to use the http://blog.csdn.net/u012453843/article/details/52987666 NodePad++ to edit the file that Linux system.
The main thing I’m going to talk about today is the problem of running the script error directly after we’ve edited the script file with NodePad++ and uploaded it to the server. For example, I’m going to edit the following script in the NodePad++ editor

#!/bin/sh
A=`ps -C nginx --no-header |wc -l`
if [ $A -eq 0 ];then
	/usr/local/nginx/sbin/nginx
	sleep 2
	if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
		killall keepalived
	fi
fi

First said the first error: syntax error: unexpected end of file, you can put that script content above script file nginx_check. Of sh (suffix, of course, you can literally a name. Sh is ok), it is important to note the last “fi”, the default is black font, we press enter increase a line, then the last “fi” color to blue, as shown in the figure below.


Editing the script we save, automatically uploaded to a Linux server, below we will execute the script in the Linux server (it is important to note that the script file must have execute permissions, you use without execute permissions chmod + x nginx_check. Sh to add execute permissions to the script), we will see the following error, tip end is illegal.

[root@bhz004 keepalived]# sh ./nginx_check.sh 
./nginx_check.sh: line 10: syntax error: unexpected end of file
[root@bhz004 keepalived]# 

Let’s look at another error: syntax error near token ‘fi’, you can paste the contents of the script directly into the script file, the last’ FI ‘is black at this time, we will not care about it.


when we execute this script, we will see the following error, indicating that line 9 “fi” has a problem.

[root@bhz004 keepalived]# sh ./nginx_check.sh 
./nginx_check.sh: line 9: syntax error near unexpected token `fi'
./nginx_check.sh: line 9: `fi'
[root@bhz004 keepalived]# 

Both of the above problems are due to the format of the.sh file in DOS format. Linux, on the other hand, can only execute scripts in Unix format. Because pressing the enter key once in DOS/Window actually enters “Enter (CR)” and “Line feed (LF)”, and Linux/ Unix only enters “Line feed (LF)”, the modified SH file will have one more CR per line, so it will report an error and not find the command when running under Linux.

You can view the format of the script file by entering the edit file interface using the command vim nginx_check-sh, as shown below.

Type “:” directly, then “set FF “after “:” as shown below

Press enter to see the script format, as shown in the figure below, and you can see that the current script format is DOS.

We need to change the format to Unix by either typing “set FF = Unix” or “Set FileFormat = Unix” as shown below.

After input, press enter to complete the format switch. Then we type “:set FF “to see the format, as shown in the figure below, and you can see that the current script format is now the” Unix “we want.

Then we can execute nginx_check-sh as shown below.

[root@bhz004 keepalived]# sh ./nginx_check.sh 
[root@bhz004 keepalived]# ps -ef | grep nginx
root       3679      1  0 19:42 ?       00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     3681   3679  0 19:42 ?       00:00:00 nginx: worker process      
root       3711   1898  0 20:23 pts/0    00:00:00 grep nginx
[root@bhz004 keepalived]#