Why is a $k$-group scheme the same things as a representable functor from the $k$-algebras? 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.
 A: This is general category theory, nothing to do with algebraic geometry. In any category $C$ with finite products, to give a group structure on an object $x$ is equivalent to lifting the functor represented by $x$ to be valued in groups. Given that $C(-,x)$ is group-valued, your main question seems to be how to construct the operations on $x$. This is by the Yoneda lemma. By assumption we have multiplication maps $C(y, x)\times C(y,x)\to C(y,x)$. If $f:y'\to y$, then the fact that $C(f,x)$ is a group homomorphism implies that our multiplications are natural. Since $C(-,x\times x)\cong C(-,x)\times C(-,x)$, altogether we get a natural transformation $C(-,x\times x)\to C(-,x)$, which arises by the Yoneda lemma from a unique morphism $m:x\times x\to x$. Similarly, we have a natural unit $C(-,*)\to C(-,x)$ which arises uniquely from $e:*\to x$, and the group axioms follow from the full faithfulness of the Yoneda embedding.
A slightly cleaner way to summarize this is that lifting $C(-,x)$ to groups is equivalent to giving it a group structure in the presheaf category, and that as a fully faithful functor preserving finite products, the Yoneda embedding reflects group objects. This also makes the converse quite clear, for what it's worth: the Yoneda embedding also preserves group objects.
