Can R paste() output \?
That is the printed representation of a single "\" in R. Clearly the right answer will depend on your end usage, but will something like this do:
> citations <- paste("title", 1:3, sep = "")
> cites <- paste("\\citep{", citations, "}", sep = "")
> writeLines(cites)
\citep{title1}
\citep{title2}
\citep{title3}
Using writeLines()
you can output that to a file using something like:
> writeLines(cites, con = file("cites.txt"))
Resulting in the following file:
$ cat cites.txt
\citep{title1}
\citep{title2}
\citep{title3}
Print string and variable contents on the same line in R
You can use paste
with print
print(paste0("Current working dir: ", wd))
or cat
cat("Current working dir: ", wd)
What is the use of 'sep' in paste command of R?
sep
is more generally applicable when you have more than two vectors of length greater than 1. If you were looking to get "something_to_paste"
, then you would be looking for the collapse
argument.
Try the following to get a sense of what the sep
argument does:
paste(a, 1:3, sep = "_")
# [1] "something_1" "to_2" "paste_3"
and compare it to collapse
:
paste(a, collapse = "_")
# [1] "something_to_paste"
R paste() not working - encountering unexpected symbol?
Not sure if this counts as an answer - you missed a comma:
paste(toString(sQuote(mylist)), collapse = "")
Paste outputs of two functions to each other in a loop in R
We can do this with a for
loop after capturing the output from CrossTable
and using append = TRUE
in both capture.output
and in the cat
by writing the contents to the same file
for(i in 1:2) {
capture.output(CrossTable(z[[i]], z$group, expected = FALSE,
format="SPSS", chisq= T, prop.t = F, dnn = c(names(z)[i], "Group")),
file = "tempnew.txt", append = TRUE)
cat(paste('cramer = ', round(assocstats(table(z[[i]], z$group))[[5]], 3)),
file = 'tempnew.txt', append = TRUE, '\n')
cat('\n\n\n********************************\n\n\n',
file = 'tempnew.txt', append = TRUE, '\n')
}
-contents of 'tempnew.txt'
Related Topics
Read List of File Names from Web into R
Ggplot2 Violin Plot: Fill Central 95% Only
How to Use Different Color Palettes for Different Layers in Ggplot2
Using: = in Data.Table with Paste()
R Bookdown - Custom Title Page
How to Specify Certificate, Key and Root Certificate with Httr for Certificate Based Authentication
Create Group Based on Fuzzy Criteria
Data.Table Objects Aren't Updated in Rstudio Environment Panel
How to Get Proportions and Counts of a Data Frame in R
How to Position Annotate Text in The Blank Area of Facet Ggplot
How to Extract Variable Names from a Netcdf File in R
Combination of Expand.Grid and Mapply
Debugging Package::Function() Although Lazy Evaluation Is Used
Ggplot: Subset a Layer Where Data Is Passed Using a Pipe
R: Apply Function to Matrix with Elements of Vector as Argument