3 added 107 characters in body
source | link

R, 49 4848 46

As an unnamed function that outputs to STDOUT. Thanks to @Flounderer for the improvement.

uses strwrap now to ident the caret to n-1. cat uses a seperator of \n rather than empty string.

function(n,xs)cat(x,"\n"s,repstrwrap(" "'^',,n-1),"^",sep=""sep='\n')

Test run

> f=function(n,xs)cat(x,"\n"s,repstrwrap(" "'^',,n-1),"^",sep=""sep='\n')
> f(29,'The caret should point here v hopefully')
The caret should point here v hopefully
                            ^
>

R, 49 48

As an unnamed function that outputs to STDOUT. Thanks to @Flounderer for the improvement.

function(n,x)cat(x,"\n",rep(" ",n-1),"^",sep="")

Test run

> f=function(n,x)cat(x,"\n",rep(" ",n-1),"^",sep="")
> f(29,'The caret should point here v hopefully')
The caret should point here v hopefully
                            ^
>

R, 49 48 46

As an unnamed function that outputs to STDOUT. Thanks to @Flounderer for the improvement.

uses strwrap now to ident the caret to n-1. cat uses a seperator of \n rather than empty string.

function(n,s)cat(s,strwrap('^',,n-1),sep='\n')

Test run

> f=function(n,s)cat(s,strwrap('^',,n-1),sep='\n')
> f(29,'The caret should point here v hopefully')
The caret should point here v hopefully
                            ^
>
2 deleted 219 characters in body
source | link

R, 4949 48

As an unnamed function that returns a string. Need to find a wayoutputs to eliminate the paste0STDOUT. Oh Thanks to @Flounderer for a string concatenation operatorthe improvement.

function(n,sx)sprintfcat(paste0x,"\n",rep("%s\n%"" ",n,"s"-1),s"^",'^'sep="")

Test run

> f=function(n,sx)sprintfcat(paste0x,"\n",rep("%s\n%"" ",n,"s"-1),s,'^')
> # Returned string
> f(29"^",'The caret should point here v hopefully'sep="")
[1] "The caret should point here v hopefully\n                            ^"
> # To stdout
> cat(f(29,'The caret should point here v hopefully'))
The caret should point here v hopefully
                            ^
>

R, 49

As an unnamed function that returns a string. Need to find a way to eliminate the paste0. Oh for a string concatenation operator.

function(n,s)sprintf(paste0("%s\n%",n,"s"),s,'^')

Test run

> f=function(n,s)sprintf(paste0("%s\n%",n,"s"),s,'^')
> # Returned string
> f(29,'The caret should point here v hopefully')
[1] "The caret should point here v hopefully\n                            ^"
> # To stdout
> cat(f(29,'The caret should point here v hopefully'))
The caret should point here v hopefully
                            ^
>

R, 49 48

As an unnamed function that outputs to STDOUT. Thanks to @Flounderer for the improvement.

function(n,x)cat(x,"\n",rep(" ",n-1),"^",sep="")

Test run

> f=function(n,x)cat(x,"\n",rep(" ",n-1),"^",sep="")
> f(29,'The caret should point here v hopefully')
The caret should point here v hopefully
                            ^
>
1
source | link

R, 49

As an unnamed function that returns a string. Need to find a way to eliminate the paste0. Oh for a string concatenation operator.

function(n,s)sprintf(paste0("%s\n%",n,"s"),s,'^')

Test run

> f=function(n,s)sprintf(paste0("%s\n%",n,"s"),s,'^')
> # Returned string
> f(29,'The caret should point here v hopefully')
[1] "The caret should point here v hopefully\n                            ^"
> # To stdout
> cat(f(29,'The caret should point here v hopefully'))
The caret should point here v hopefully
                            ^
>