Package 'ch'

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

Help Index


ch: some small functions

Description

It's about some functions in chem and other questions.


Remove '>' and '+' from the console and add '#' to the run result.

Description

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.

Usage

console_cl(prefix = "#>")

Arguments

prefix

The prefix for code.The default is '#>'. You can edit it according to your own preference, but '#' should be the first character.

Value

the result of the run is saved to the clipboard.

Author(s)

Chai


about csv2vcf

Description

A simple method to generate vcf file.

Usage

csv2vcf(csv_file, vcf_file, header = FALSE)

Arguments

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 read.csv, the default is FALSE.

Value

NULL. t will be saved in a file with the suffix vcf.


Create a picture with a transparent background.

Description

Use the ImageMagick command line to convert the PDF saved by ggplot2 to PNG format with a transparent background and to set the resolution.

Usage

ggpng(x, dpi = 600, ...)

ggPNG(x, p, dpi = 600, ...)

Arguments

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

Details

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.

Value

You will get a PNG file with the result drawn by ggplot2.

Author(s)

Chai


Ground-State spectral term

Description

Use such a function to calculate the spectral term, and it can show the number of the spectral term.

Usage

ground_state(x)

state_1(l, n)

state_2(x)

Arguments

x

'p2','p3','d2','d5','f2',...

l

the l:0,1,2,3,4,5,...

n

the number of electrons.

Value

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.

Author(s)

Chai

References

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.

Examples

ground_state("p2")
ground_state("f3")
state_2("p2")
state_2("d3")

tex format and $$...$$

Description

output to Console and clipboard. You can better check the correctness of the output.

Usage

lat_fmt(x)

latex_fmt(x)

Arguments

x

symbol object,for more see ysym.

Value

lat_fmt() will output to Console. latex_fmt() will output to clipboard.

Author(s)

Chai


Calculate The pH of weak acid/base

Description

Calculate the pH of weak acid or base.

Usage

monoa(ka, c, digits = 2)

monob(ka, c, digits = 2)

mono(ka, c, digits = 2, acid = TRUE, kw = 1e-14)

Arguments

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

Value

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.

Examples

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)

Draw the Periodic table

Description

use ggplot2 to draw the periodic table.

Usage

period_table()

Value

A ggplot2 object.

Author(s)

Chai


Use ggplot2 to plot a table

Description

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!

Usage

plot_table(Str, ncol, byrow = TRUE)

Arguments

Str

some expressions

ncol

the number f col

byrow

logical, the default is

Value

It will output a ggplot object that contains a table.

Author(s)

Chai

Examples

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)

change path in MS windows

Description

transfer 'D:\ R\ b\' to 'D:/R/b', and write to the clipboard.

Usage

re_path()

Value

Transfer path to the clipboard.


Read the text to data.frame

Description

Read the strings and transform to the data.frame.

Usage

read.txt(text, header = TRUE, ...)

Arguments

text

strings

header

logical value

...

for more see read.table

Value

A data.frame

Author(s)

Chai


Round of Numbers that is improved.

Description

Round : rounding off to five in double. round_1 and Round2: to achieve the standard sense of rounding.

Usage

Round(x, n = 0)

round_1(x, n)

Round2(x, n)

Arguments

x

vector or matrix

n

digits

Value

It rounds the values and output to console.

Author(s)

Chai


Read string into a vector

Description

Read data into a vector from a string.

Usage

scan.str(string)

Arguments

string

a string that number is separated by ' '.

Value

A vector that contains numbers.

Author(s)

Chai

Examples

m <- "12 23 45 78 90 89 97"
scan.str(m)

An easy way to show colors in ggplot2

Description

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.

Usage

show_color(
  colors,
  ncol,
  byrow = TRUE,
  label = FALSE,
  number = FALSE,
  size = 1,
  border = "black"
)

Arguments

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

Author(s)

Chai


Use ggplot to draw ruler

Description

You can draw a ruler that uses ggplot2. Also It's funny and you can get a lot of methods from this function.

Usage

show_ruler(len = 5)

Arguments

len

the length of ruler

Value

A ggplot2 object.

Author(s)

Chai


state

Description

About state, new function!

Usage

stat(x)

Arguments

x

Like: d5,p2,p3,f3

Value

the state content.

Examples

stat("d5")
stat("p2")
stat("p3")
stat("f3")

Extracting coefficients from polynomials

Description

sym2ploy can extract coefficients from polynomials and gives the roots of polynomials. The roots is calculated from polyroot and the polyroots function.

Usage

sym2poly(x, var = "x")

sym2coef(x, var = "x")

Arguments

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'.

Value

sym2poly() returns Coefficients and the roots. sym2coef() only returns coefficients.

Author(s)

Chai

Examples

sym2poly("3*x^2 + x^5 + x*8")
sym2poly("3*x^2 + x^5 + 2*x^5")

Generating multiple symbols at once

Description

It may be faster than using ysym.

Usage

symb(..., quite = FALSE)

Arguments

...

The multiple vectors.

quite

If FALSE, it will show the message in the end.

Value

The multiple symbols.

Author(s)

Chai

Examples

library(Ryacas)
symb(x, y, z)
str(x)