Title: | About some Small Functions |
---|---|
Description: | The solution to some common problems is proposed, as well as a summary of some small functions. In particular, it provides a useful function for some problems in chemistry. For example, monoa(), monob() and mono() function can be used to calculate The pH of weak acid/base. The ggpng() function can save the PNG format with transparent background. The period_table() function will show the periodic table. Also the show_ruler() function will show the ruler. The show_color() function is funny and easier to show colors. I also provide the symb() function to generate multiple symbols at once. The csv2vcf() function provides an easy method to generate a file. The sym2poly() and sym2coef() function can extract coefficients from polynomials. |
Authors: | Hailong Chai [aut] |
Maintainer: | Hailong Chai <[email protected]> |
License: | GPL-3 |
Version: | 0.1.2 |
Built: | 2025-03-08 04:31:04 UTC |
Source: | https://github.com/tsiamut/ch |
First you need to copy the console area to the clipboard, then run the console_cl() function to add a comment to the line where the output is, and to cancel the > on the original line. Finally, the result of the run is saved to the clipboard.
console_cl(prefix = "#>")
console_cl(prefix = "#>")
prefix |
The prefix for code.The default is '#>'. You can edit it according to your own preference, but '#' should be the first character. |
the result of the run is saved to the clipboard.
Chai
A simple method to generate vcf file.
csv2vcf(csv_file, vcf_file, header = FALSE)
csv2vcf(csv_file, vcf_file, header = FALSE)
csv_file |
The csv file contains names and phone numbers. The style is like this: Joey 18100 Hans 12788 Tim 34689 The first column is the name, the second column is the phone number corresponding to each person. The above is an example, and it is not true personal information summary. |
vcf_file |
The vcf file to create. |
header |
For more see |
NULL. t will be saved in a file with the suffix vcf.
Use the ImageMagick command line to convert the PDF saved by ggplot2 to PNG format with a transparent background and to set the resolution.
ggpng(x, dpi = 600, ...) ggPNG(x, p, dpi = 600, ...)
ggpng(x, dpi = 600, ...) ggPNG(x, p, dpi = 600, ...)
x |
A file name that does not have a suffix. |
dpi |
The default dpi is 600. You can enhance the dpi value to produce a higher resolution PNG file. |
... |
see :ggsave |
p |
ggplot2 object |
You need to install ImageMagick! Please check if the ImageMagick is added to the environment variable.
this ggplot2 object will automatically add a theme with a transparent background.
You will get a PNG file with the result drawn by ggplot2.
Chai
Use such a function to calculate the spectral term, and it can show the number of the spectral term.
ground_state(x) state_1(l, n) state_2(x)
ground_state(x) state_1(l, n) state_2(x)
x |
'p2','p3','d2','d5','f2',... |
l |
the l:0,1,2,3,4,5,... |
n |
the number of electrons. |
It is a display of the results of the calculation of the spectral term. For more explanation, please refer to the structural chemistry. The ground_state() function will tell you the ground state that spectral term of equal electrons. The state_1() and state_2() will tell you the spectral term of equal electrons.
Chai
The method of state_1() and state_2() function is from: DOI:10.14159/j.cnki.0441-3776.1985.11.020 And the url is: https://t.cnki.net/kcms/detail?v=3uoqIhG8C44YLTlOAiTRKqd0WnNPv0wTDjtDUwHroNz8ZoQZVLjnVKa9t-3R3F8t9DSW1fOAkwcAF8JZi9EnOU8ccrbY3bNC&uniplatform=NZKPT You can get more details from this essay.
ground_state("p2") ground_state("f3") state_2("p2") state_2("d3")
ground_state("p2") ground_state("f3") state_2("p2") state_2("d3")
output to Console and clipboard. You can better check the correctness of the output.
lat_fmt(x) latex_fmt(x)
lat_fmt(x) latex_fmt(x)
x |
symbol object,for more see |
lat_fmt() will output to Console. latex_fmt() will output to clipboard.
Chai
Calculate the pH of weak acid or base.
monoa(ka, c, digits = 2) monob(ka, c, digits = 2) mono(ka, c, digits = 2, acid = TRUE, kw = 1e-14)
monoa(ka, c, digits = 2) monob(ka, c, digits = 2) mono(ka, c, digits = 2, acid = TRUE, kw = 1e-14)
ka |
ionization constant. |
c |
concentration. |
digits |
digit of the output. |
acid |
if TRUE, it is equivalent to monoa function; if FALSE, it is equivalent to monob function. |
kw |
the default is 1e-14 |
monoa() will return the pH of weak acid, the monob() will return the pH of weak base. And you can also use the mono() function to replace the monoa() function and monob() function.
monoa(1.4 - 6, 2.35e-2) monoa(2.78e-8, 0.01) monob(1.35e-5, 0.01) monob(2.4 - 6, 1e-4)
monoa(1.4 - 6, 2.35e-2) monoa(2.78e-8, 0.01) monob(1.35e-5, 0.01) monob(2.4 - 6, 1e-4)
use ggplot2 to draw the periodic table.
period_table()
period_table()
A ggplot2 object.
Chai
You can use plot_table to draw table in ggplot2,
but it only applies to expressions(see expression
).
For more information , you can see plotmath
.
But it's a ggplot2 object!
plot_table(Str, ncol, byrow = TRUE)
plot_table(Str, ncol, byrow = TRUE)
Str |
some expressions |
ncol |
the number f col |
byrow |
logical, the default is |
It will output a ggplot object that contains a table.
Chai
a1 <- c( "x %*% y", "x %/% y", "alpha", "sigma", "beta", "x == y", "frac(x,y)", "x %up% y", "hat(x)", "symbol(a)", "underline(x)" ) plot_table(a1, 2) plot_table(a1, 3)
a1 <- c( "x %*% y", "x %/% y", "alpha", "sigma", "beta", "x == y", "frac(x,y)", "x %up% y", "hat(x)", "symbol(a)", "underline(x)" ) plot_table(a1, 2) plot_table(a1, 3)
transfer 'D:\ R\ b\' to 'D:/R/b', and write to the clipboard.
re_path()
re_path()
Transfer path to the clipboard.
Read the strings and transform to the data.frame.
read.txt(text, header = TRUE, ...)
read.txt(text, header = TRUE, ...)
text |
strings |
header |
logical value |
... |
for more see |
A data.frame
Chai
Round : rounding off to five in double. round_1 and Round2: to achieve the standard sense of rounding.
Round(x, n = 0) round_1(x, n) Round2(x, n)
Round(x, n = 0) round_1(x, n) Round2(x, n)
x |
vector or matrix |
n |
digits |
It rounds the values and output to console.
Chai
Read data into a vector from a string.
scan.str(string)
scan.str(string)
string |
a string that number is separated by ' '. |
A vector that contains numbers.
Chai
m <- "12 23 45 78 90 89 97" scan.str(m)
m <- "12 23 45 78 90 89 97" scan.str(m)
the same function can see
show_col
, but it is a
ggplot2 object. You can use it like the show_col()
function in scales package, but it can save by ggsave() function.
show_color( colors, ncol, byrow = TRUE, label = FALSE, number = FALSE, size = 1, border = "black" )
show_color( colors, ncol, byrow = TRUE, label = FALSE, number = FALSE, size = 1, border = "black" )
colors |
string about colors |
ncol |
the number f col |
byrow |
logical |
label |
logical |
number |
logical, the default is |
size |
the size of label, the default is 1. |
border |
The color of border |
Chai
You can draw a ruler that uses ggplot2. Also It's funny and you can get a lot of methods from this function.
show_ruler(len = 5)
show_ruler(len = 5)
len |
the length of ruler |
A ggplot2 object.
Chai
About state, new function!
stat(x)
stat(x)
x |
Like: d5,p2,p3,f3 |
the state content.
stat("d5") stat("p2") stat("p3") stat("f3")
stat("d5") stat("p2") stat("p3") stat("f3")
sym2ploy can extract coefficients from
polynomials and gives the roots of polynomials.
The roots is calculated from polyroot
and
the polyroots
function.
sym2poly(x, var = "x") sym2coef(x, var = "x")
sym2poly(x, var = "x") sym2coef(x, var = "x")
x |
The polynomials,for examples, '3x^2 + 6x^6 + 2 + 25*x'. |
var |
The var from polynomials, for examples, the var of '3x^2 + x^6 + x8 + x*5^2' is 'x'. |
sym2poly() returns Coefficients and the roots. sym2coef() only returns coefficients.
Chai
sym2poly("3*x^2 + x^5 + x*8") sym2poly("3*x^2 + x^5 + 2*x^5")
sym2poly("3*x^2 + x^5 + x*8") sym2poly("3*x^2 + x^5 + 2*x^5")
It may be faster than using ysym
.
symb(..., quite = FALSE)
symb(..., quite = FALSE)
... |
The multiple vectors. |
quite |
If FALSE, it will show the message in the end. |
The multiple symbols.
Chai
library(Ryacas) symb(x, y, z) str(x)
library(Ryacas) symb(x, y, z) str(x)