Assume $k$ is a field. I've been trying to understand clearly the definition of an affine $k$-group scheme.
There are two different definitions that I have found in the literature. They are:
(1) An affine $k$-group scheme is a group object in the category of affine $k$-schemes.
(2) An affine $k$-group scheme is a representable functor $G : k-\mathbf{Alg} \to \mathbf{Grp}$.
I wanted to know how these two definitions are equivalent. Looking around for an explanation, I've found the following remark in T. Szamuely's book Galois Groups and Fundamental Groups, page 212.
Remark 6.1.2 In the last chapter we defined a group scheme over $k$ as a group object in the category of $k$-schemes, i.e. a $k$-scheme $G$ together with $k$-morphisms $m : G \times G \to G$ (‘multiplication’), $e : \mathrm{Spec} (k) \to G$ (‘unit’) and $i : G \to G$ (‘inverse’) subject to the usual group axioms. These morphisms induce a group structure on the set $G(S) := \mathrm{Hom}_k(S,G)$ of $k$-morphisms into $G$ for each $k$-scheme $S$. Therefore the contravariant functor $S \mapsto \mathrm{Hom}_k(S,G)$ on the category of $k$-schemes represented by $G$ is in fact group-valued. Restricting it to the full subcategory of affine $k$-schemes we obtain a covariant functor $R \mapsto \mathrm{Hom}_k(\mathrm{Spec} (R),G)$. Proposition 5.1.5 shows that when $G = \mathrm{Spec} (A)$ is itself affine, this is none but the functor above.
I've tried to understand what the author is saying in the above remark, but there are some things that I need help with understanding.
I can see how the morphisms would induce a group structure on the set $G(S) = \mathrm{Hom}_k(S, G)$ and so it is clear that the contravariant functor $S \mapsto G(S)$ is group-valued. However, I don't what the author is saying in the next few lines and it is not clear how from this line of reasoning do we get that the group object can be identified with / gives a representable functor of definition (2).
Also, how do we go in the opposite direction from a representable functor to a group object?
I would be so grateful if someone can explain in some detail what is going on. Thank you.
Note: (a) When the author writes "this is none but the functor above", he means to say the functor in definition (2). (b) I think "we obtain a covariant functor $R \mapsto \mathrm{Hom}_k(\mathrm{Spec} (R),G)$" is a typo and the author meant to say contravariant functor $\mathrm{Spec}(R) \mapsto \mathrm{Hom}_k(\mathrm{Spec} (R),G)$.
====================================================================
Edit: Thanks to @Joppy for the correction that there is no typo and consequently clarifying what the author meant. When $G=\mathrm{Spec}(A)$ is an affine group scheme, we have
$$\mathrm{Hom}_{k-sch}(\mathrm{Spec}(R), \mathrm{Spec}(A)) \cong \mathrm{Hom}_{k-Alg}(R, A),$$ because the categories of affine $k$-schemes is equivalent to the opposite category of $k$-algebras. Then we get a functor $R \mapsto \mathrm{Hom}_{k-Alg}(R, A)$ and we can identify $G$ with this functor. I still don't quite clearly understand how to go in the opposite direction.