str() prints first no matter the order in R
<p>I am writing a function that would give the dim() and str() of a given dataset. </p>

<pre><code>JustfunFun &lt;- function(.csv) {
  csv &lt;- read.csv(.csv)
  dimVal &lt;- dim(csv)
  print("The dimension of the dataset is:")
  strVal &lt;- str(csv)
  print("The structute of the dataset is:")
  headVal &lt;- head(csv)
  return(list(dimVal, strVal, headVal))
}
</code></pre>

<p>Ideally, the output must have the dimension first, the structure second and then the head of dataset.</p>

<p>But the output is as follows:</p>

<pre><code>&gt; JustfunFun("tips.csv")
[1] "The dimension of the dataset is:"
'data.frame':   244 obs. of  8 variables:
 $ obs    : int  1 2 3 4 5 6 7 8 9 10 ...
 $ totbill: num  17 10.3 21 23.7 24.6 ...
 $ tip    : num  1.01 1.66 3.5 3.31 3.61 4.71 2 3.12 1.96 3.23 ...
 $ sex    : Factor w/ 2 levels "F","M": 1 2 2 2 1 2 2 2 2 2 ...
 $ smoker : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
 $ day    : Factor w/ 4 levels "Fri","Sat","Sun",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ time   : Factor w/ 2 levels "Day","Night": 2 2 2 2 2 2 2 2 2 2 ...
 $ size   : int  2 3 3 2 4 4 2 4 2 2 ...
[1] "The structute of the dataset is:"
[1] "The head of the dataset is:"
[[1]]
[1] 244   8

[[2]]
NULL

[[3]]
  obs totbill  tip sex smoker day  time size
1   1   16.99 1.01   F     No Sun Night    2
2   2   10.34 1.66   M     No Sun Night    3
3   3   21.01 3.50   M     No Sun Night    3
4   4   23.68 3.31   M     No Sun Night    2
5   5   24.59 3.61   F     No Sun Night    4
6   6   25.29 4.71   M     No Sun Night    4

&gt; 
</code></pre>

<p>How do I tackle this problem? </p>