Questions tagged [substitution]

The action of replacing something with another thing.

The action of replacing something with another thing.

1879 questions
13
votes
2 answers

deparse(substitute()) within function using data.table as argument

If I want do deparse the argument of a function for an error or a warning, something strange is happening if the argument is converted to a data.table within the function: e <- data.frame(x = 1:10) ### something strange is happening foo <-…
nachti
  • 1,086
  • 7
  • 20
13
votes
4 answers

how to replace latex macros with their definitions (using latex)

How can I replace all occurrence of user defined latex macros with their definitions? For example, given this file old.tex \newcommand{\blah}[2]{#1 \to #2} ... foo \blah{egg}{spam} bar ... how to generate the file below in an automatic…
Yoo
  • 17,526
  • 6
  • 41
  • 47
12
votes
2 answers

Creating expression tree in R

The substitute function in R creates a language object in the form of a tree that one can parse. How can I create the tree from scratch using list or else to then give it to eval? # substitute gives a tree representation of the expression a=1;…
tlamadon
  • 970
  • 9
  • 18
12
votes
1 answer

Post-cache substitution with Page.Render overriding

The context I have an Asp .Net web application with some pages that inherit from a base class "BasePage". This BasePage class inherits from System.Web.ui.Page and I've overriden the Render method so that I can intercept the HTML stream before it is…
Benjamin Simon
  • 444
  • 4
  • 14
12
votes
0 answers

typesafe config substitution for relative paths

Is there a way to use relative paths in substitution instead of absolute ones? I want to write this, which doesn't work: service { password = "qwerty" url = "http://example.com?user=John&password="${password} } Works only this case: service { …
Yaroslav
  • 4,543
  • 5
  • 26
  • 36
12
votes
1 answer

sed error "Invalid range end"

I run this substitution command on Ubuntu 12.04. $ sed -e "s/([a-zA-Z0-9.-/\\ :]+)/\1/g" However, the following error is raised. sed: -e expression #1, char 27: Invalid range end I can remember the same expression works on MacOSX. Can you…
JJD
  • 50,076
  • 60
  • 203
  • 339
12
votes
4 answers

In VIM, is it possible to use the selected text in the substitute clause without retyping it?

Let's say I have a word selected in visual mode. I would like to perform a substitution on that word and all other instances of that word in a file by using s//. Is there a way to use the highlighted text in the s//stuff/ part without having…
Jordan Parmer
  • 36,042
  • 30
  • 97
  • 119
11
votes
1 answer

docker-compose --env-file is not working at all

I'm trying this: https://docs.docker.com/compose/environment-variables/#substitute-environment-variables-in-compose-files and as stated by the documentation, this is my docker-compose.yml: services: web: image: "${IMAGE}" This is my .env.dev…
Joseph
  • 1,029
  • 13
  • 26
11
votes
3 answers

How do I substitute with an evaluated expression in Perl?

There's a file dummy.txt The contents are: 9/0/2010 9/2/2010 10/11/2010 I have to change the month portion (0,2,11) to +1, ie, (1,3,12) I wrote the substitution regex as follows $line =~ s/\/(\d+)\//\/\1+1\//; It's is printing…
Sekhar
  • 5,614
  • 9
  • 38
  • 44
11
votes
5 answers

how to substitute part of a string in python?

How to replace a set of characters inside another string in Python? Here is what I'm trying to do: let's say I have a string 'abcdefghijkl' and want to replace the 2-d from the end symbol (k) with A. I'm getting an error: >>> aa = 'abcdefghijkl' >>>…
user63503
  • 6,243
  • 14
  • 41
  • 44
10
votes
1 answer

vim call function on a group in substitute string

how to call a function from the substitute string in vim? When i have: %s/regex/string/g and i want the group as argument and replace it with the return value of the function: %s/regex/call function(\1)/g so the group #1 will be the argument of the…
microo8
  • 3,568
  • 5
  • 37
  • 67
10
votes
2 answers

remove emoji from string in R

I have a list of tweets, many of which contain emojis that need to be removed. What would be the most effective method for doing this in R? I have tried the following method which is supposed to substitute all words beginning with "\" with a…
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
10
votes
2 answers

Replace matches according to the pattern that was matched

Given a set of regular expressions, is there a simple way to match multiple patterns, and replace the matched text according to the pattern that was matched? For example, for the following data x, each element begins with either a number or a…
jbaums
  • 27,115
  • 5
  • 79
  • 119
10
votes
2 answers

String replacement (to lowercase) in Bash 4.3.33 - bad substitution error

I'm trying to change uppercase to lowercase using string replacement in bash, but i'm getting a bad substitution error. > a=HEY > echo $a HEY > echo ${a,,} -bash: ${a,,}: bad substitution # desired output is hey I've seen similar questions to…
A-K
  • 147
  • 1
  • 1
  • 9
10
votes
7 answers

How do I perform multiple replacements with Perl?

I have Perl code: my $s = "The+quick+brown+fox+jumps+over+the+lazy+dog+that+is+my+dog"; I want to replace every + with space and dog with cat. I have this regular expression: $s =~ s/\+(.*)dog/ ${1}cat/g; But, it only matches the first occurrence…
user332951
  • 359
  • 1
  • 3
  • 18